Home > Language Reference > System Functions > Allocate

Allocate

The Allocate function allocates memory space for data used by External DLL functions within a script.

Usage

Used to allocate memory before using External$ function.

Syntax

address=Allocate(<size>)

Parameters

<size>. integer, size of the space to allocate (size in bytes).

Return value

address, unsigned, pointer to the allocated memory. Use Dim function to declare at the beginning of the script the unsigned variable.

If the allocation fails, the return value is 0.

See also

Constants and Variables

Examples

dim MemPointer as unsigned
MemPointer=Allocate(80)

'This script displays the folder name where Windows is installed.
'It calls the GetWindowsDirectoryA API function, using a pointer.
'Declare a variable to hold the memory address
dim pointer as unsigned
'reserve a 64-byte memory space
pointer=allocate(64)
'prepare a string to place in memory
wdir$=" "
'writes the zero-terminated string to memory
ret=PokeString(pointer,wdir$,0)

'In Win32, an A must be added to function which return a string
a=External("kernel32","GetWindowsDirectoryA",pointer,64)
'read the string through its memory address
var$=peekString$(pointer)
'Display the returned string
msgbox(var$)