[fpc-devel] Aligned dynamic arrays

Jonas Maebe jonas at freepascal.org
Sat Mar 30 22:02:46 CET 2019

On 30/03/2019 14:59, Ryan Joseph wrote:
>> On Mar 30, 2019, at 9:10 AM, Jonas Maebe <jonas at freepascal.org> wrote:
>> FPC always aligns data to its alignment as specified by the platform ABI. {$align x} can be used to limit this alignment to a lower number. It cannot be used to increase it.
> This caused us quite a bit of problems with the Metal framework because we needed padding fields also.

How is this done in the Metal C headers?

> If you saw the original bug report we’re trying to make a custom alignment (of 4k) for the Metal framework. I propose the syntax because it solves the problem of how to assign alignment and there is a precedent for it (i.e. $align).

No, I missed that. In that case, a vector type won't help. The best way 
then is, as has been mentioned elsewhere in this thread, a getmem 
variant that supports allocating memory on an aligned boundary. Similar 
to how unix platforms have posix_memalign.

This falls outside the scope of direct support in the language, so a 
solution like Anthony's is better in this case if you want to 
encapsulate it completely.

> Can you give some examples of the vector type? I don’t exactly know what you guys are referring to.

A vector type is basically a (fairly small) array of integer or floating 
point types. All current desktop (and many embedded) CPUs have special 
execution units that operate on all elements of such vectors in 
parallel, which means you can get better performance.


More information about the fpc-devel mailing list