[fpc-pascal] Pre-allocated TFPGList or similar

Michael Van Canneyt michael at freepascal.org
Sun Nov 24 10:14:54 CET 2019

On Sun, 24 Nov 2019, Sven Barth via fpc-pascal wrote:

> Am 23.11.2019 um 23:42 schrieb Ryan Joseph via fpc-pascal:
>> I need a pre-grown list which I can put (not insert!) items into at indexes 
> without getting "List index out of bounds" errors. For example I want to 
> start with a list that has 10 empty indexes:
>> list := TList.Create(10); // 10 empty slots!
>> list[5] := someItem;
>> Is this possible using any list type in the RTL? Actually I'd rather just 
> disable all the out of bounds errors because  I need some performant which 
> isn't making more checks than need be. I want to use a heap-based list 
> because the it may need to grow later.
> What you're looking for is the Count property. Setting it is supported 
> by the untyped lists in Classes, the generic ones in FGL as well as 
> those in Generics.Collections.

Better yet, use Capacity.

Count is meant to set the number of slots actually used.
Capacity is the number of allocated slots.


More information about the fpc-pascal mailing list