[fpc-pascal] Array clearing

Ryan Joseph ryan at thealchemistguild.com
Wed Apr 5 04:49:34 CEST 2017


> On Apr 4, 2017, at 10:10 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> While your statement regarding allocation might be true you must not
> forget that a dynamic array consists of a meta data block (length,
> reference count) that is located directly in front of the data block. So
> even if the memory blocks would be allocated consecutively then there'd
> still be the meta data blocks inbetween.
> 
> If you already know that your dynamic arrays only have a specific size
> (for matrices used in games that should usually be the case) then you're
> better off with using a static array:
> 
> === code begin ===
> 
> type
>  TMatrix = array[0..2, 0..2, 0..2] of LongInt;
> 
> === code end ===
> 
> There you can use FillChar() as much as you want as that is indeed a
> single memory block containing 9 LongInt elements.

Yeah after all this talk, I’m going to use array[0..0, 0..0, 0..0] and allocate the memory myself to avoid overhead and confusion. Thanks for explaining everything to me but this time going low level makes the most sense.

Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list