StructureAlignment hidden feature?

I cant find anything in the documentation about StructureAlignment

I did however find it in a blog post here

Are there any other hidden/undocumented features like this?

I’m specifically looking for Structure Unions to be able to cope with

Any pointers, or should I just manipulate memoryblocks?


Please file a bug report about this
There used to be an entire section about structure alignment as follows

===Structure Alignment===
‘‘Structure alignment’’ refers to aligning the data at a memory offset equal to some multiple of the word size. Data alignment can increase the computer’s performance.

Structures can be aligned using Attributes. You add the attribute “StructureAlignment” to a structure and use one of the legal values: 0, 1, 2, 4, 8, 16, 32, 64, and 128 as the value. A value of 0 indicates that the compiler should perform a natural alignment, which ensures that the structure will be laid out correctly for a given platform’s ABI rules.

To specify a structure alignment, add an attribute to the Attribute List in the Inspector. Specify “StructureAlignment” in the Name field and enter the desired alignment value.

But a structure wont let you do what a C union does

Thanks Norman, will do.

Thanks for the info on union too, I guess its onto memoryblocks.

Gimme 5 minutes to test something out :stuck_out_tongue:

Roger, I filed the feedback://showreport?report_id=47397 already regarding missing StructureAlignment information.

the trick here will be how the MS apis expect things aligned
and that will be CRUCIAL
I have no idea if they will expect packed or not (StructureAlignment 1)
And to be honest I would be kind of surprised if they do

But IF they do then you could define 2 structures that end up, in total # of bytes, being the same size

For instance you could have structure1 that is

   field1 as int32 
   field2 as string*10
   field3 as uint8

and structure2 that is

   field1 as uint8
   field2 as int32
   field3 as string*10

when these are both set to PACKED alignment they both occupy 15 consecutive bytes

And that means you can do

		dim s1 as structure1
		s1.field1 = &h0102030405060708
		s1.field2 = "1234567890"
		s1.field3 = &h88
		dim s2 as structure2 = Ctype(s1, structure2)

and basically reinterpret those bytes using the second structure’s layout (which is kind of what a union does)

What I dont know off the type of my head is whether a union compiled for the Windows API is PACKED or not

If not then this likely wont work because you get different padding bytes in different places and so the structures may end up being different total #'s of bytes (ie/ Here the first with structure alignment 0 is 16 bytes and the second 20)

Thanks for thinking about it Norman. I think the problem will be that the structs are so vastly different it will be a pain to pick apart the data. I get an EventType returned on all different events so I should be able to use that to pick apart the memoryblock, it just wont be as elegant as using structures. I’ll see if Christian wants to look into it as an upgrade to MSB Util before I Module for this. Thanks again.

Have you looked to see if WFS already has this defined ?

TBH though, the StructureAlignment reference was just a fish to see if there was some other functionality that wasn’t documented that could help me :wink:

Ooo, I forgot about that, I shall have a butchers now, ta.

Ah yes it does, kind of (memoryblock), I shall have to digest the info, thanks.


[quote=321287:@JulianS]TBH though, the StructureAlignment reference was just a fish to see if there was some other functionality that wasn’t documented that could help me :wink:
Its hidden for a reason :stuck_out_tongue:
JK - I’m not aware of anything that was omitted/skipped like this that might help
Being able to do a “reinterpret” cast is about as close as I could think of

Umm whatttt ???

Heh, sorry, I said I needed sleep :wink:

Well, well, I think I might have just found another hidden feature.

Pre-pending a Structure entry with an underscore omits it from the list when using that structure, great for padding a structure!

Is that a feature or a bug as the Size seems to have a meltdown!