CObArray Class

Supports arrays of CObject pointers.

class CObArray : public CObject




Constructs an empty array for CObject pointers.




Adds an element to the end of the array; grows the array if necessary.


Appends another array to the array; grows the array if necessary.


Copies another array to the array; grows the array if necessary.


Returns a temporary reference to the element pointer within the array.


Frees all unused memory above the current upper bound.


Returns the value at a given index.


Gets the number of elements in this array.


Allows access to elements in the array. Can be NULL.


Gets the number of elements in this array.


Returns the largest valid index.


Inserts an element (or all the elements in another array) at a specified index.


Determines if the array is empty.


Removes all the elements from this array.


Removes an element at a specific index.


Sets the value for a given index; array not allowed to grow.


Sets the value for a given index; grows the array if necessary.


Sets the number of elements to be contained in this array.



CObArray::operator [ ]

Sets or gets the element at the specified index.

These object arrays are similar to C arrays, but they can dynamically shrink and grow as necessary.

Array indexes always start at position 0. You can decide whether to fix the upper bound or allow the array to expand when you add elements past the current bound. Memory is allocated contiguously to the upper bound, even if some elements are null.

Under Win32, the size of a CObArray object is limited only to available memory.

As with a C array, the access time for a CObArray indexed element is constant and is independent of the array size.

CObArray incorporates the IMPLEMENT_SERIAL macro to support serialization and dumping of its elements. If an array of CObject pointers is stored to an archive, either with the overloaded insertion operator or with the Serialize member function, each CObject element is, in turn, serialized along with its array index.

If you need a dump of individual CObject elements in an array, you must set the depth of the CDumpContext object to 1 or greater.

When a CObArray object is deleted, or when its elements are removed, only the CObject pointers are removed, not the objects they reference.

Note Note

Before using an array, use SetSize to establish its size and allocate memory for it. If you do not use SetSize, adding elements to your array causes it to be frequently reallocated and copied. Frequent reallocation and copying are inefficient and can fragment memory.

Array class derivation is similar to list derivation. For details on the derivation of a special-purpose list class, see the article Collections.

Note Note

You must use the IMPLEMENT_SERIAL macro in the implementation of your derived class if you intend to serialize the array.

Header: afxcoll.h