Size of a TList

Hi!
How do I find the number of elements in a TList? It doesn’t seem to be any method for that in the class definition. However, looping over the list just to know its size seems very inefficient.

TList::GetSize() sounds vaguely related.

This thread is 10 years old but I couldn’t find any answer besides looking through documentation, so here goes.
TList inherits from TCollection, which in turn has both GetSize() and GetEntries() methods. GetSize() returns the capacity of the TCollection (ie. how many entries memory has been allocated for), while GetEntries() returns the actual number of entries in the TCollection.

1 Like

Same here ! Thanks @Sandro729

It sounds trivial, but… is it possible to improve something here @bellenot ?

What do you mean? Improve what?

@Sandro729 TCollection::GetEntries, TCollection::GetSize and TCollection::Capacity return the same fSize value (note: “GetEntries” and “GetSize” are virtual so that they can be overridden in derived classes, but that’s not the case in TList).

Wait then what does the fSize value represent? Capacity or the number of used slots? And how would you get the other one?

Or, per chance, are capacity and number of slots used actually the same value for a TList but they might be different in other classes?