Fons Rademakers writes: > > - how does the TObjArray know the number of elements in it? It is smart: > > it doesn't do compression when one of its objects is deleted therefore > > it allows "holes" in its structure. > > Does it mean that to get the number of objects in TObjArray one has to > > calculate this number explicitly by iterating over the collection each time > > he needs it? > > > The are two cases: > - no holes: TObjArray::GetEntriesFast() returns number of objects in > array. Note: this is <= size of array (returned by TObjArray::Capacity() > or GetSize()). > - holes: TObjArray::GetEntries() returns number of objects in array > (done by looping over array, thus expensive). > Hi Fons, wouldn't it make sense to have in TObjArray (or in one of its base collection classes ?) one more data member - number of objects in the array? In terms of timind efficiency this doesn't add much - just one increment/decrement per insertion/deletion. On the other hand it is extremely useful to have number of objects in the collection as a data member and not only as a result of calculation. Regards, Pasha.
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:21 MET