# classname_fieldname_alloc(vector)

> This function allocates pages in the database to hold vector elements.

### Prototype

>         MCO_RET	classname_fieldname_alloc(	/*IN*/ classname *handle,
>                                /*IN*/ uint2 size  );

### Arguments

handle | A pointer to a classname handle
size | A `uint2` that specifies the number of elements that will be stored in the vector

### Description

> This function causes eXtremeDB to allocate pages in the database to hold the vector elements, which are subsequently assigned with `classname_fieldname_put_range()` methods. If invoked on an existing object, the vector is resized to `size`, truncating the vector if `size` is less than the current vector size. If `size` is greater than the current size the vector is moved to a new larger space; the space previously used by the vector is lost, so care should be taken not to reallocate vectors too frequently.

> The classname_pack() API can be used to defragment objects after multiple vector reallocations, or the `autocompact_threshold` database parameter can be set to cause autocompaction of an object on transaction commit if the objects size exceeds the specified threshold.

> Note that this method is not generated for fixed size arrays.

### Return Codes

MCO_S_OK | The vector was allocated successfully
MCO_E_ACCESS | Transaction is `READ_ONLY`
MCO_E_TRANSACT |
MCO_E_DELETED |
MCO_E_NOMEM |
MCO_ERR_OBJECT_HANDLE |
MCO_ERR_TRN_LONG |
MCO_ERR_TRN |

Related Topics