How to align memory in Objective-C?

Apple recommends that your data be 16-byte aligned when you use the Accelerate Framework. How do you do this in practice?

If I have an int[10000]; array int[10000]; is there a pragma ? How to align this with 16 bytes?

+7
ios objective-c accelerate-framework
source share
2 answers

To align the data, you need to use the #pragma pack . To get 16 byte alignment, you will need to use:

#pragma pack(push,16) ... your data structure here ... #pragma pack(pop)

I would advise you to learn more about alignment, because you might get corrupted data.

+8
source share

malloc and friends always have 16 byte alignment. Among other reasons for supporting vectors.

If you have an array int [10000]; then most likely it should not be a fixed size, not on the stack, but allocated using malloc. And then it has 16 bytes.

+3
source share

All Articles