(*
 * Title:   heap.h
 * Purpose: provide malloc-style heap allocation in a flex block
 *
 *)

# ifndef __heap_h
# define __heap_h

# ifndef __os_h
# include "os.h"
# endif


(* ---------------------------- heap_init ----------------------------------
 * Description:   Initialises the heap allocation system.
 *
 * Parameters:    BOOL heap_shrink -- if TRUE, the flex block will be shrunk
 *                                    when possible after heap_free()
 * Returns:       void.
 * Other Info:    You must call flex_init before calling this routine.
 *
 *)
procedure heap_init(heap_shrink : boolean); extern;


(* ---------------------------- heap_alloc ---------------------------------
 * Description:   Allocates a block of storage from the heap.
 *
 * Parameters:    unsigned int size -- size of block to be allocated
 * Returns:       pointer to allocated block (or 0 if failed).
 * Other Info:    This uses the flex module to allocate wimp-supplied heap
 *                space. If the heap moves as the result of an extension
 *                or flex can't extend the heap then 0 is returned.
 *
 *)
function heap_alloc(size : integer) : pointer; extern;


(* ---------------------------- heap_free ----------------------------------
 * Description:   Free previously allocated block of heap storage.
 *
 * Parameters:    void *heapptr -- pointer to block to be freed
 * Returns:       possible error condition.
 * Other Info:    none.
 *
 *)
procedure heap_free(heapptr : pointer); extern;

#endif

(* end of heap.h *)
