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.

=== code begin ===

list := TList.Create;
list.Count := 10;
list[5] := someItem;

=== code end ===

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to