CObArray::GetData

Use this member function to gain direct access to the elements in the array.

const CObject** GetData( ) const;  
CObject** GetData( );

Return Value

A pointer to the array of CObject pointers.

Remarks

If no elements are available, GetData returns a null value.

While direct access to the elements of an array can help you work more quickly, use caution when calling GetData; any errors you make directly affect the elements of your array.

The following table shows other member functions that are similar to CObArray::GetData.

Class

Member Function

CByteArray

const BYTE* GetData( ) const;BYTE* GetData( );

CDWordArray

const DWORD* GetData( ) const;DWORD* GetData( );

CPtrArray

const void** GetData( ) const;void** GetData( );

CStringArray

const CString* GetData( ) const;CString* GetData( );

CUIntArray

const UINT* GetData( ) const;UINT* GetData( );

CWordArray

const WORD* GetData( ) const;WORD* GetData( );

Example

See CObList::CObList for a listing of the CAge class used in all collection examples.

CObArray myArray;

// Allocate memory for at least 32 elements.
myArray.SetSize(32, 128);

// Add elements to the array.
CAge** ppAge = (CAge**) myArray.GetData();
for (int i = 0; i < 32; i++, ppAge++)
   *ppAge = new CAge(i);

// Only keep first 5 elements and free extra (unused) bytes.
for (int i = 5; i < myArray.GetCount(); i++)
{
   delete myArray[i]; // free objects before resetting array size.         
}
myArray.SetSize(5, 128);
myArray.FreeExtra(); // only frees pointers.

#ifdef _DEBUG
    afxDump.SetDepth(1);
    afxDump << _T("myArray: ") << &myArray << _T("\n");
#endif      

Requirements

Header: afxcoll.h

See Also

Reference

CObArray Class

Hierarchy Chart

CObArray::GetAt

CObArray::SetAt

CObArray::ElementAt

Other Resources

CObArray Members