255 of 286
241 System.Alloc Type Function returning UnsignedInteger Invocation System.Alloc(numBytes) Parameter Method Type Description numBytes ByVal integral The size of the requested allocation. Discussion This function allocates a block of memory from the heap of the specified size and returns the address of the first byte of the block. If a block of the specified size cannot be allocated, zero is returned. The block can be returned to the heap using the subroutine System.Free(). This function and the block of memory it returns must be used with great care. If your program fails to deallocate the block using System.Free() when it is no longer needed, the heap may eventually be exhausted. Since space for strings is also allocated from the heap, exhaustion may cause string operations to fail. Moreover, if your program writes to memory outside of the bounds of the block, the heap data structures may be corrupted. This may cause future heap allocation requests to fail. For native mode devices (e.g. the ZX-24n) a heap allocation may fail if the heap size is set too small compared to the needs of your application. To aid in determining a sufficient heap size the System Library function System.HeapHeadRoom() may be used to discover the amount of space in the heap that has not yet been used at the time of the call. Example Dim addr as UnsignedInteger addr = System.Alloc(50) [other code here that uses the allocated block] Call System.Free(addr) addr = 0 Compatibility This function is not available in BasicX compatibility mode. See Also System.Free