LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

another DLL struct member alignment question


This is a question related to a previous post:

http://forums.ni.com/ni/board/message?board.id=170&message.id=126491&query.id=22005#M126491

Similar to the previous post, I need to pass Labview clusters to a DLL compiled with the default struct alignment. I'm using Visual C++ 7.1 on Windows XP, and I believe the default struct alignment is 8 bytes. At any rate, following the suggestions outlined in that post I added padding to several clusters, and got them working to pass data to and from the DLL.

However, I get errors from the last cluster, which seem to be due to misalignment. The only difference I can see between it and the others is that this cluster contains another cluster. Are there any special considerations for this case? Or, is there possibly something else I'm doing wrong? The contained cluster is a set of 7 int32s, so I don't see how it would need any padding. I did try to add various amounts of padding after the cluster anyway, without success.

I did find a workaround of making the cluster the last element in the top-level cluster's order. But I'd like to understand what's going on, and I may want several clusters contained in one later. I attached the files for my test app, if there are any problems or missing files please let me know.

Thanks for any help,

Adam
0 Kudos
Message 1 of 4
(2,769 Views)

Hey,

I am not very good at passing clusters to DLLs but I am good at searching for stuff I need ;). I think this link may be helpful to you.

Regards,

Ankita 

0 Kudos
Message 2 of 4
(2,734 Views)
Thanks for the extra link! I'm also not very good at struct member alignment issues, but Rolf's gem of wisdom to use the #pragma pack keywords for the Labview structs in that thread seems to solve my problem, without needing any special padding in the clusters. Looking farther online it seems there could be a performance hit, but it's not noticable for what I'm doing.

Thanks again,

Adam
0 Kudos
Message 3 of 4
(2,719 Views)


@asweet wrote:
Thanks for the extra link! I'm also not very good at struct member alignment issues, but Rolf's gem of wisdom to use the #pragma pack keywords for the Labview structs in that thread seems to solve my problem, without needing any special padding in the clusters. Looking farther online it seems there could be a performance hit, but it's not noticable for what I'm doing.

Thanks again,

Adam


Intel CPUs are fairly good in accessing data on non-aligned addresses. But they also have quite a complex section in their microcode to achieve this. Most other CPUs do bother less about improving unaligned data access and there the performance hit can be usually seen, with RISC CPUs like SPARC having really a huge performance hit.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 4
(2,705 Views)