basic.%malloc

C Function/BASIC Program, Releases: AP/Unix

Allocates memory.

Syntax

variable=(char*)%malloc( size )

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.

Example

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

See Also

Command Name Type Description
basic.cfunction Definition Declare a list of C functions.
basic.%read C Function Reads from a Unix file.
basic.%free C Function Frees memory.
tcl.environ Verb: Access Manipulates Unix shell environment variables from TCL.
basic.%putenv C Function Assigns value to environment variable.
tcl.disc Verb: Access Disconnect from virtual machine.

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.