Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



How to resize an array

In a CArrayFixFlat<class T> or a CArrayFixSeg<class T> array, the number of elements in an array can be changed, either decreased or increased, using the ResizeL() function.

In the following code fragment, ResizeL() changes the size of an array so that it contains only one element. If the array originally had more than one element, then this call to ResizeL() deletes all elements from position one onwards, leaving only the element at position zero.

CArrayFixFlat<TElement>* fixflat;
fixflat = new (ELeave) CArrayFixFlat<TElement>(3);
...
fixflat->ResizeL(1);

Call ResizeL() again to change the size of the array to contain a greater number of elements, in this case three. If the array originally had only one element (for example), this call to ResizeL() constructs two new elements at positions one and two. In this example, the new elements inserted at positions one and two are TElement type objects, constructed using the TElement default constructor. It is therefore essential that a default constructor exists before using this function.

fixflat->ResizeL(3);

There is an overloaded variant of ResizeL() which takes a reference to a TElement object. A bit-wise copy of this referenced object supplies the new elements. In the following code fragment the two extra elements are bit-wise copies of the theElement object.

_LIT(KTextXXX,"XXX");
theElement.iData = KTextXXX;
fixflat->ResizeL(5,theElement);