5 messages in net.java.dev.jna.usersRe: [jna-users] Seemingly correct map...
FromSent OnAttachments
Andrew PullinJan 15, 2009 11:25 pm 
Jorge Nieto-MadridJan 16, 2009 4:25 am 
Timothy WallJan 16, 2009 6:34 am 
Jorge Nieto-MadridJan 16, 2009 8:13 am 
Timothy WallJan 16, 2009 8:37 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Seemingly correct mapping results in heap space errorActions...
From:Timothy Wall (twal@dev.java.net)
Date:Jan 16, 2009 6:34:02 am
List:net.java.dev.jna.users

While JNA does have some overhead managing structs, I wouldn't think that 100 small structs would cause a memory problem. However, you can easily check by substituting byte[300] for your TRgbPix[100] (assuming the struct has no padding and has 1-byte alignment), and then extract the bytes manually.

This should at least indicate whether the memory issue is due to the structure array.

Also make sure that your library implements StdCallLibrary if SMXM7X_API is defined to use the stdcall calling convention.

primitive arrays are interchangeable with Pointer/PointerType and java.nio.Buffer as pointer types (i.e. void*). In Java you can even declare multiple type mappings for the same native method (where in C you'd have to cast the argument to a generic type).

On Jan 16, 2009, at 2:26 AM, Andrew Pullin wrote:

Hey folks. I've managed to work through most of the problem's I'm hit with JNA so far, but I'm a little stuck on this one. I need to interface with a camera, which has a DLL interface. Here's the function I need to use:

//////// C code TRgbPix* SMXM7X_API CxBayerToRgb(void *BayerMatrix, int ScW, int ScH, int AlgId, TRgbPix *Frame); ////////

My java mapping: TRgbPix CxBayerToRgb(byte[] BayerMatrix, int ScW, int ScH, int AlgID, TRgbPix[] Frame);

And pertinent struct: ///// C code typedef struct _TRgbPix { BYTE b; BYTE g; BYTE r; } TRgbPix; ///////////

The Java version of that struct I am using is: public static class TRgbPix extends Structure { public static class ByValue extends TRgbPix implements Structure.ByValue { } public byte b; public byte g; public byte r; }

I'm invoking it as: byte[] buffer = new byte[100]; // Some stuff here to fill buffer TRgbPix[] frameOut = new TRgbPix[100]; SMXLibrary.INSTANCE.CxBayerToRgb(buffer, 10, 10, 2, frameOut);

The problem I get is a 10 second hang, followed by: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.lang.Class.getDeclaredFields0(Native Method) at java.lang.Class.privateGetDeclaredFields(Class.java:2291) etc

I'm fairly sure that it's not some silly indexing / row&column problem, as in using the function incorrectly. In the C code, the buffer is a BYTE array. Any ideas? I'm not sure what to do about the void * type being an argument, when it supposed to be a byte array.