class CObArray : public CObject

The CObArray class supports arrays of CObject pointers. 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.

The elements of a CObArray object must fit in one 64K segment together with approximately 100 allocation overhead bytes. If CObject pointers are 16-bit near pointers (as they are in the small and medium memory models), then an array size limit is about 32,000 elements, but because there is only one data segment, the objects themselves will probably exhaust memory before the array does. If CObject pointers are 32-bit far pointers (as they are in the compact and large memory models), then an array size limit is about 16,000 elements.

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.

#include <afxcoll.h>

See Also

CStringArray, CPtrArray, CByteArray, CWordArray, CDWordArray

Derivation

Array class derivation is similar to list derivation. For details on the derivation of a special-purpose list class, see the tutorial in the Class Library User's Guide.

Note:

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