10 messages in net.java.dev.jna.usersRe: [jna-users] setting structure ali...
FromSent OnAttachments
Rui CaridadeDec 8, 2008 6:07 pm 
Timothy WallDec 8, 2008 7:18 pm 
Rui CaridadeDec 8, 2008 8:26 pm 
Timothy WallDec 8, 2008 8:54 pm 
Rui CaridadeDec 8, 2008 9:05 pm 
Rui CaridadeDec 10, 2008 5:11 pm.log
Timothy WallDec 10, 2008 6:05 pm 
Rui CaridadeDec 10, 2008 6:13 pm 
Rui CaridadeDec 11, 2008 2:50 am 
Timothy WallDec 11, 2008 5:24 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] setting structure alignmentActions...
From:Rui Caridade (waih@yahoo.com)
Date:Dec 8, 2008 8:26:27 pm
List:net.java.dev.jna.users

Thank you :) I've tested a bit more and it all seems to work :) Jna is great :) For correctness sake, this was what i did:

protected static void setAlignment(Structure c ){ ((Memory)(c.getPointer())).align(4); }

and then for instance on Vector

SIMDx86Vector v =(SIMDx86Vector) Structure.newInstance(SIMDx86Vector.class); SIMDx86Factory.setAlignment(v); return v;

Is this correct way to do it ? :) Thank you again for your fast and unvaluable help

________________________________ From: Timothy Wall <twal@dev.java.net> To: use@jna.dev.java.net Sent: Tuesday, December 9, 2008 3:18:39 AM Subject: Re: [jna-users] setting structure alignment

You'll need to explicitly ensure that the memory allocated for the structure is
aligned, using Memory.align(4).

Hello. I'm currently working on creating bindings for libSIMDx86
(http://simdx86.sourceforge.net/). Some structures are aligned to the 16th byte for instance

typedef struct SIMDx86Vector { float x, y, z; float __SIMD_pad__; /* Padding to 16th byte for SIMD operations (3DNow!/SSE)
*/ } SIMDx86Vector ALIGNED;

Where aligned is

#if defined(__GNUC__) #define ALIGNED __attribute__(( aligned(16) )) #elif defined(_MSC_VER) #define ALIGNED __declspec(align(16)) #endif

My implementation is as follows

public class SIMDx86Vector extends Structure {

float x, y, z; float __SIMD_pad__; /* Padding to 16th byte for SIMD operations (3DNow!/SSE)
*/

public SIMDx86Vector allocate(){ return (SIMDx86Vector) Structure.newInstance(this.getClass()); } }

My question is do i need to do anything more on the Java side? All the best and thanks in advance