- DelphiTools - https://www.delphitools.info -

First phase of dynamic arrays refactoring completed

The first phase of dynamic arrays refactoring mentioned previously [1] is now complete, with dedicated implementations in place for all the base types. A single interface (IScriptDynArray) is now the only common ground.

The current state has been frozen in Release snapshot DWScript v21.3.11 [2] on the GitHub mirror.

Decoupled implementations

While the dedicated implementations are mostly similar right now, generics were not used:

The implementation divergence is most visible right now for the “array of boolean” type: it is implemented though TBits, with a memory usage of 1 bit per element. This means “array of boolean” will now use 192 times less memory !

TBits will eventually be replaced by a more direct implementation, with bit shifting support (for inserts/deletes). Eventually whole-array Boolean operations will be introduced.

Arrays of String & Interface (which also means arrays of script objects or script dynamic arrays) will probably stay as Delphi-dynamic arrays for the medium term.

Virtual Memory for large arrays

Arrays of Integer and Floats will likely diverge from the Delphi-dynamic-array implementation to a lower level one, which would be able to leverage highly-aligned virtual memory.

This would facilitate AVX use, as AVX instructions work on high-ly aligned memory.

But in 64bits, this would allow a leveraging the huge virtual address space, by pre-reserving virtual memory, so that an array can be grown/reallocated without needing to be copied.

JIT Compiler

The 64bit JIT has partial support for the new dynamic arrays, but this is quite limited at the moment.
The 32bit JIT does not support them yet, so array operations will be interpreted.