xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

ASizeAlloc()

Pre-allocates memory for an array.

Syntax

ASizeAlloc( <aArray>, <nCount>  ) --> aArray

Arguments

<aArray>
This is the array to pre-allocate memory for.
<nCount>
A numeric value specifying the number of elements to reserve memory for.

Return

The function returns the array <aArray>.

Description

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.

Info

See also:AAdd(), Array(), ALenAlloc(), ASize()
Category: Array functions , xHarbour extensions
Source:vm\arrayshb.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe