Structure Size Question

Hi, I’m trying to pass in a structure into a external function which takes in a pointer. Normally i would put the structure into a memory block and pass in the pointer to the memoryblock. However this structure is defined as follows in xcode

[code]typedef struct
// Positions in pixel space
// (e.g. a value of 100 indicates 100 pixels from the center)
vector_float2 position;

// Floating-point RGBA colors
vector_float4 color;

} AAPLVertex;[/code]

In Xojo it would be this

[code]Structure AAPLVertex
position as vector_float2
col as vector_float4
End Structure

Structure vector_float2
value1 as cgfloat
value2 as cgfloat
End Structure

Structure vector_float4
value1 as cgfloat
value2 as cgfloat
value3 as cgfloat
value4 as cgfloat
End Structure

Populating a vector_float4 in xcode and printing sizeof(value) returns 16. In xojo the structure says it is size 16 and returns a “size” of 32 at runtime.
Populating a AAPLVertex in xcode sizeof(value) returns 32, in xojo it says the structure is 24 and the returned size at runtime is 48.

What am i doing wrong that i get such different values? Where is the other 8 bytes going in xcode?
If i was to populate a memory block with an array of AAPLVertex datas how would I write it out?

Running 64bit on macOS 10.12


in 64bit CGFloat is 8bytes… (4bytes in 32bit)
so vector_flag2 is 16bytes, vector_float4 is 32bytes, making AAPLVertex 48 bytes

A CFloat in Xcode is the same size (assuming it too is a 64bit environment)

Seems the Xojo IDE doesn’t honor the build flag (32 vs 64bit) when calculating a structure size

The odd part is in xcode sizeof(vector_float2) = 8 and sizeof(vector_float4) = 16 but sizeof(AAPL_Vertex) = 32

The reason behind this is that the data is being packed (they are not actually floats but some other crazy structure from a simd library)
vector_float4 cannot output at a byte offset that is not divisible by 16. vector_float2 cannot be output unless it’s offset is divisible by 8 and so on.


The structure editor lets you toggle showing 32 or 64 bit sizes regardless of the build settings. Otherwise you’d have to change your build settings to see the different sizes. Click the gear icon an toggle “show 64 bit sizes”. You can toggle this on and off to see the 32 and 64 bit sizes of your structures at design time.

Is the structure editor confirmed to be working correctly on macos (unlike in windows)?

It is, once you find that switch Jason mentions (it should automatically conform to the build settings in my opinion)