%malloc() function

The %malloc() function allocates a memory block of size bytes and returns the address of this block.

Syntax

var = (char*)%malloc(size)

Description

The memory is freed by the %free() built-in. If the system fails to allocate memory, a null pointer is returned.

If the FlashBASIC program terminates, the space allocated by %malloc is not released automatically. This feature can be used to create static data, live across program executions. The TCL environ command uses this fact.

Memory allocated by %malloc can be freed by exiting the D3 process.

Example(s)

ptr=(char*)%malloc(2048)
if ptr=0 then stop ’cannot allocate memory’