Malloc Function

Action

Allocates memory blocks.

Include file

Kernel.bdh

Syntax

Malloc (in nSize : number ): number;

Return value

Pointer to the allocated space. Unless Silk Performer is able to allocate the specified amount of memory, the simulation is aborted.

Parameter Description
nSize Size of allocated space in bytes

Example

dcltrans
  transaction TMalloc
  var
    nBuffer: number;
  begin
    // allocate a buffer of 10 bytes
    nBuffer := Malloc(10);
    write("memory successfully allocated"); writeln;

    // free memory referenced by nBuffer
    Free(nBuffer);
    write("memory released"); writeln;
  end TMalloc;

Output

memory successfully allocated
memory released