Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Can I initialize TStCollection with a given size?

Help
2013-10-01
2013-10-01
  • Thomas Mueller
    Thomas Mueller
    2013-10-01

    Is there any way to initialize a TStCollection with a given size? Like setting TList.Capacity?
    I need to initialize it with the numbers from 0 to SomeMaximum, so with TList, I would use

    List.Capacity := SomeMaximum + 1;
    for i := 0 to SomeMaximum do
    List.Add(Pointer(i));

    With TStCollection I currently have this code:

    for i := 0 to SomeMaximum do
    Coll[i] := Pointer(i);

    This is taking some unnecessary time because the collection has to allocate pages every time it runs out of space. I would like to reduce this overhead by creating all necessary pages initially.