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


Can I initialize TStCollection with a given size?

  • Thomas Mueller
    Thomas Mueller

    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

    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.