Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to reserve space in a fixed flat array

Adding elements to a flat array of elements having the same length, a CArrayFixFlat<class T> type, may cause the array buffer to be re-allocated to accommodate the extra elements. This can fail for lack of memory.

If it is important to guarantee that the process of inserting elements cannot fail at the time of insertion, then the necessary space in the array buffer should be reserved in advance. This allows any out of memory situation to be handled before starting to add elements to the array.

SetReserveL() reserves sufficient space to accommodate the required number of elements, in this case ten.

CArrayFixFlat<TElement>* fixflat;
fixflat = new (ELeave) CArrayFixFlat<TElement>(3);
...
fixflat->SetReserveL(10);

If the array already contains five elements, then another five elements can be added to the array and be guaranteed not to fail for lack of memory.