[fpc-pascal] Feature announcement: Dynamic array extensions

Martok listbox at martoks-place.de
Thu Jun 7 12:42:05 CEST 2018


> 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.

-- 
Regards,
Martok

Ceterum censeo b32079 esse sanandam.




More information about the fpc-pascal mailing list