basic.%malloc C Function/BASIC Program

basic.%malloc

Command basic.%malloc C Function/BASIC Program
Applicable release versions: AP/Unix
Category BASIC Program (486)
Description allocates a memory block of "size" bytes and returns the address of this block.
The memory is freed by the "%free()" built-in. If the system fails to allocate memory, a NULL pointer is returned.

If the Pick/BASIC program terminates, the malloc'ed space is not released automatically. This feature can be used to create 'static' data, live across program executions. The TCL command 'environ' uses this fact.

"malloc'ed" memory may be "free'd" by "exit"ing the Pick process.
Syntax variable=(char*)%malloc( size )
Options
Example
ptr=(char*)%malloc( 2048 )
if ptr=0 then stop 'cannot allocate memory'
Purpose
Related basic.cfunction
basic.%read
basic.%free
tcl.environ
basic.%putenv
tcl.disc