LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

dll struct member alignment

I need information about the struct member alignment setting when compiling DLLs for use with LabVIEW. In my DLL, I also make function calls to a rendering library, VTK, that was compiled with 8 byte alignment. My DLL will only work if compiled with 8 byte alignment. If I compile it with 1 byte, I get obvious bad struct alignment issues and functions that perform deep copies to struct members cause fatal memory errors, which makes sense. But I'm confused since the LabVIEW documentation says that the struct member alignment should be set to 1 byte for all projects.
So why does it work with 8 byte?
Am I taking a risk by using 8 byte?
If I only make calls to the 8 byte compiled library then is it even an issue?
Should I compile the rendering library with 1 byte so that I can compile my DLL with 1 byte as well?
Are LabVIEW CIN functions compiled with 1 byte; is that the reason?

I guess I just need to know why DLLs for LabVIEW should be compiled with 1 byte alignment and if this rule can be bent.

Any information is greatly appreciated.
thank you,
Louis
0 Kudos
Message 1 of 2
(3,227 Views)


@lou 83 wrote:
I need information about the struct member alignment setting when compiling DLLs for use with LabVIEW. In my DLL, I also make function calls to a rendering library, VTK, that was compiled with 8 byte alignment. My DLL will only work if compiled with 8 byte alignment. If I compile it with 1 byte, I get obvious bad struct alignment issues and functions that perform deep copies to struct members cause fatal memory errors, which makes sense. But I'm confused since the LabVIEW documentation says that the struct member alignment should be set to 1 byte for all projects.
So why does it work with 8 byte?
Am I taking a risk by using 8 byte?
If I only make calls to the 8 byte compiled library then is it even an issue?
Should I compile the rendering library with 1 byte so that I can compile my DLL with 1 byte as well?
Are LabVIEW CIN functions compiled with 1 byte; is that the reason?

I guess I just need to know why DLLs for LabVIEW should be compiled with 1 byte alignment and if this rule can be bent.

Any information is greatly appreciated.
thank you,
Louis




LabVIEWs structures are indeed packed, with 1 byte alignment on most systems. (I think that Sparc is an exception to this as it has very bad performance when accessing a memory address which is not a multiple of its size. But 1 byte alignment is not bad at all if you need a different alignment you really only have to investigate the structures and find out where the compiler would fill in extra bytes and add them on the LabVIEW diagram to the cluster yourself. As a rule a value is aligned to a multiple of its own size or the compiler specified alignment, whichever is smaller. 8 byte alignment does for instance not mean that an int32 would be aligned to a multiple of 8 byte but to a multiple of 4 bytes only as that is its own size. Only doubles would be aligned to 8 bytes really (and long long, but they are not directly supported by LabVIEW.)

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 2
(3,219 Views)