heap_init()

Purpose

Creates and initialises the heap used by DP4 functions.

Syntax

void heap_init(size_t size);

Parameters

size_t size

size of the heap required

Description

This function works very differently for 16 and 32 bit programs.

  • In 16 bit programs heap_init() creates a heap area by reducing the size of the stack by the amount specified or by the maximum possible if size is set to 0 bytes. The stack may be reduced to a maximum of 4KBytes, so this function is inappropriate if your program needs a larger stack. If heap_init() is used in a program, it is necessary to increase the size of the stack explicitly. For a DP4 program you can call:

    KENTCURS -MAXSTACK

    or

    KENTCURS -STACK <nnnn>

    Alternatively, you can specify a larger stack at link time.

    If enabled, Compiler stack checking is unaffected by this operation, i.e. it will cause a fault if your program uses more than the new 4K stack limit.

  • For 32 bit programs the function works by calling the underlying C implementation of malloc() (or possibly an OS function like HeapAlloc()). If 0 is passed as the size, the size specified in the global variable df_heap_size is used. You can declare and initialise this variable yourself. The default df_heap_size is quite small - a little below 64K bytes.

Return values

None

See also

freex()

This function should only be called once per program. Only the first call does anything. You can grow the DP4 heap by allocating memory some other way and adding to the heap with freex().