Compartilhar via


CObArray Class

Supports arrays of CObject pointers.

class CObArray : public CObject

Members

Public Constructors

Name

Description

CObArray::CObArray

Constructs an empty array for CObject pointers.

Public Methods

Name

Description

CObArray::Add

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

CObArray::Append

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

CObArray::Copy

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

CObArray::ElementAt

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

CObArray::FreeExtra

Frees all unused memory above the current upper bound.

CObArray::GetAt

Returns the value at a given index.

CObArray::GetCount

Gets the number of elements in this array.

CObArray::GetData

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

CObArray::GetSize

Gets the number of elements in this array.

CObArray::GetUpperBound

Returns the largest valid index.

CObArray::InsertAt

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

CObArray::IsEmpty

Determines if the array is empty.

CObArray::RemoveAll

Removes all the elements from this array.

CObArray::RemoveAt

Removes an element at a specific index.

CObArray::SetAt

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

CObArray::SetAtGrow

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

CObArray::SetSize

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

Public Operators

Name

Description

CObArray::operator [ ]

Sets or gets the element at the specified index.

Remarks

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

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

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

Inheritance Hierarchy

CObject

CObArray

Requirements

Header: afxcoll.h

See Also

Reference

CObject Class

Hierarchy Chart

CStringArray Class

CPtrArray Class

CByteArray Class

CWordArray Class

CDWordArray Class