I made the changes to increase the dynamic arrays in powers of 2, and that increased the speed a lot! Now Delphi's memory manager works 70% faster than FastMM, maybe because FMM is debugging the processes, and I can add 1 million elements without getting an exception error.

Now I want to speed up the deletion of elements. I supposed it would be a good idea to release the memory in the same way, and modified my algorithm to half the reserved block when the last used element is lower than half of the length.

Also, my algorithm allows batching processes, and I'm thinking on making a deletion list, so I can mark the removed elements and dispose them later... but there are several options I could use, some of them:

1. Creating a linked list of pointers or indexes to elements for deletion. This would waste a lot of memory, and would be too slow to use with my algorithm.

2. Adding a field to the element's "record" type that allows marking it as deleted, but that would waste 1 byte per element.

3. Making an array of bits (or using Delphi's bit array class) to map deleted elements. Maybe this is the option that requires less resources.

This is where calls like AllocMem, ReAllocMem and FreeMem step in, as they have only limitation of your system memory unlike setlength.
Oh, they are also much faster than setlength Wink Only problem is you'd be using pointers which make it slightly more complicated.
Yes, it's not as handy as SetLentgh, but it would be possible to mask the memory block with an array. I'll try those functions too, thanks for sharing the idea.