[fpc-devel] Aligned dynamic arrays

Ryan Joseph ryan at thealchemistguild.com
Thu Mar 28 15:17:20 CET 2019

> On Mar 28, 2019, at 4:17 AM, Sven Barth via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> The order should be 
> [padding] [header] [data]
> with the offset being part of the header. This way you reduce the changes needed to only those that allocate/free an array.

Yeah that’s probably the better idea because it’s less intrusive.

> Also I don't think that a simple "do alignment or not" will be sufficient. What kind of alignment do you pick? What if the user needs more alignment? So it would probably be best to add a new SetLengthAligned of which the second argument is the alignment followed by the lengths. 

That’s correct, there’s an alignment parameter also, not just a boolean. The header may need to include the desired alignment also for copy operations but I’m not sure yet.

Since the offset is going to be part of the header now (and possibly the desired alignment) does it matter that this will affect all dynamic arrays? It’s probably only 4 bytes but still worth considering.

> In dynarr.inc you then add a new setlength variant that takes an additional alignment parameter while the old one without alignment calls the new one with alignment 1.
> Note: the compiler can call the new one for both variants, but the old one is required for bootstrapping, so you could surround that with {$if not defined(ver3_0) and not defined(ver3_2)}.

You mean if the compiler is < 3.0 then don’t parse the new SetLength variant?

	Ryan Joseph

More information about the fpc-devel mailing list