4 messages in net.java.dev.jna.usersRe: [jna-users] Nested Structure alig...
FromSent OnAttachments
Francis FernandezApr 11, 2008 8:31 am 
Timothy WallApr 11, 2008 8:39 am 
Francis FernandezApr 11, 2008 8:47 am 
Timothy WallApr 11, 2008 9:22 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] Nested Structure alignmentActions...
From:Timothy Wall (twal@dev.java.net)
Date:Apr 11, 2008 9:22:50 am
List:net.java.dev.jna.users

On Apr 11, 2008, at 11:47 AM, Francis Fernandez wrote:

I'm sorry. Here are the relevant structs from the API:

/// struct for image format typedef struct _VRmImageFormat { /// width in pixels VRmDWORD m_width; /// height in lines VRmDWORD m_height; /// color format enum VRmColorFormat m_color_format; /// bit combination of enum VRmImageModifier values int m_image_modifier; }VRmImageFormat;

16 bytes.

/// struct for image container typedef struct _VRmImage { /// image format struct VRmImageFormat m_image_format; /// pointer to image buffer VRmBYTE* mp_buffer; /// pitch = number of bytes from (x,y) to (x,y+1) VRmDWORD m_pitch; /// timestamp of image in ms since last VRmUsbCamRestartTimer() double m_time_stamp; /// private = additional internal data void* mp_private; }VRmImage;

36 bytes (used). JNA pads to 8-byte boundary due to the "double" field, giving the structure a size of 40 bytes.

When I attempt to grab a new image from the camera, it returns successful, and the object's toString() looks like this:

VRmImage(allocated@0x2fb2830 (40 bytes)) { VRmImageFormat m_image_format@0=VRmImageFormat(allocated@0x2fb2830 (40 bytes) (shared from allocated@0x2fb2830 (40 bytes))) { NativeLong m_width@0=48121264 NativeLong m_height@4=0 int m_color_format@8=0 int m_image_modifier@c=0 } Pointer mp_buffer@10=null NativeLong m_pitch@14=0 double m_time_stamp@18=0.0 Pointer mp_private@20=null }

The problem here is that the VRmImageFormat field is taking up the entirety of the Structure (at least, that's what it looks like to me). The format object is supposed to be inline in the image object, as I understand it, but it doesn't seem to be aligning properly. How can I best get this issue sorted out? Thank you.

The "40 bytes" is simply indicating the size of the allocated memory, not the size of the structure itself. Notice that the offset of "mp_buffer" is 16 bytes, exactly the size of the nested structure, and the nested structure starts at offset zero of the outer structure.

Double check that the sizes of the structures match what sizeof() gives you in C, and that the field offsets are the same (if not, there's a JNA bug).