Partager via


CObArray::SetSize

Establishes the size of an empty or existing array; allocates memory if necessary.

void SetSize( 
   INT_PTR nNewSize, 
   INT_PTR nGrowBy = -1  
);

Parameters

  • nNewSize
    The new array size (number of elements). Must be greater than or equal to 0.

  • nGrowBy
    The minimum number of element slots to allocate if a size increase is necessary.

Remarks

If the new size is smaller than the old size, then the array is truncated and all unused memory is released. For efficiency, call SetSize to set the size of the array before using it. This prevents the need to reallocate and copy the array each time an item is added.

The nGrowBy parameter affects internal memory allocation while the array is growing. Its use never affects the array size as reported by GetSize and GetUpperBound.

If the size of the array has grown, all newly allocated CObject * pointers are set to NULL.

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

Class

Member Function

CByteArray

void SetSize( INT_PTR nNewSize, int nGrowBy = -1 );

    throw( CMemoryException* );

CDWordArray

void SetSize( INT_PTR nNewSize, int nGrowBy = -1 );

    throw( CMemoryException* );

CPtrArray

void SetSize( INT_PTR nNewSize, int nGrowBy = -1 );

    throw( CMemoryException* );

CStringArray

void SetSize( INT_PTR nNewSize, int nGrowBy = -1 );

    throw( CMemoryException* );

CUIntArray

void SetSize( INT_PTR nNewSize, int nGrowBy = -1 );

    throw( CMemoryException* );

CWordArray

void SetSize( INT_PTR nNewSize, int nGrowBy = -1 );

    throw( CMemoryException* );

Example

See the example for CObArray::GetData.

Requirements

Header: afxcoll.h

See Also

Reference

CObArray Class

Hierarchy Chart