[fpc-pascal] Feature announcement: Dynamic array extensions

Florian Klämpfl florian at freepascal.org
Thu Jun 7 21:12:35 CEST 2018


Am 07.06.2018 um 12:42 schrieb Martok:
>> What actually happens is that the memory is released back to the heap
>> (but *not* to the OS, at least on Linux), with the result that
>> concatenating elements will introduce a substantial hit particularly if
>> space for a new element allocated from the heap isn't contiguous.
> Writing a preallocating wrapper *where needed* for heavily grown arrays is
> fairly simple.
> 
> The thing is: it's rarely worth it ;-)
> I recently did that for a wavefront mesh loader that appends vertices one-by-one
> to an array, and for a scene with some 400k vertices, the difference was just
> some milliseconds out of several seconds overall.
> Turns out the allocator usually finds a spot where the array doesn't need to
> actually be copied around for a while, and the pure bookkeeping of realloc is
> very cheap.
> 

It would be worth though to think about extending the memory manager to make use of the realloc syscall (not sure about 
its actual name) on some OSes as the OS can "copy" memory to a different virtual address by just re-mapping pages. I 
think at least linux really does this.



More information about the fpc-pascal mailing list