xHarbour Reference Documentation > Function Reference |
Pre-allocates memory for an array.
ASizeAlloc( <aArray>, <nCount> ) --> aArray
The function returns the array <aArray>.
Function ASizeAlloc() pre-allocates memory for <nCount> number of elements of an array. This improves dynamically growing arrays when elements are added to the array using AAdd().
Note: the function does not change the number of elements of <aArray>, it reserves only memory for them, thus optimizing memory usage with dynamic arrays.
See also: | AAdd(), Array(), ALenAlloc(), ASize() |
Category: | Array functions , xHarbour extensions |
Source: | vm\arrayshb.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example creates an empty array and pre-allocates // memory for 1000 elements. Note that the examples ends // with a runtime error, since element 100 does not exist. PROCEDURE Main LOCAL aArray := {} ASizeAlloc( aArray, 1000 ) ? ALenAlloc( aArray ) // result: 1000 AAdd( aArray, 10 ) ? Len( aArray ) // result: 1 ? aArray[100] // runtime error RETURN
http://www.xHarbour.com