[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
*-------------------------------------------------------------------------
* heap.hdr -- FORCE FAQ example of how to use allocated memory
*
* heap.hdr is the header file for a non-constrained heap manager.
*-------------------------------------------------------------------------
* RCSid = "$Header: G:\HEAP\RCS\heap.hdr 0.10 1992/04/07 05:10:37 holmesda Exp holmesda $"
*-------------------------------------------------------------------------
* Here's the structure of a the heap header in C notation:
*
* typedef struct heap_header
* {
*    int          heap_size;        /* current max size of heap         */
*    int          nodes;            /* current number of nodes in heap  */
*    void       * compare;          /* pointer to a compare function    */
*    void       * heap_buffer;      /* pointer to the actual heap       */
* } Heap;
*-------------------------------------------------------------------------
#ifndef HEAP_HDR
#define HEAP_HDR

#include alloc.hdr
*-------------------------------------------------------------------------
* Prototypes....
*-------------------------------------------------------------------------
#ifndef HEAP_TOOLS
#ifndef HEAP_CREATE_PRG
FUNCTION LONG heap_create PROTOTYPE    && returns pointer to a heap header
   PARAMETERS UNTYPED compare_function
#endif

PROCEDURE heap_destroy PROTOTYPE
   PARAMETERS VALUE LONG heap_header, VALUE LOGICAL kill_data

FUNCTION LOGICAL heap_insert PROTOTYPE
   PARAMETERS LONG heap_header, VALUE LONG ptr

FUNCTION LONG heap_index PROTOTYPE
   PARAMETERS VALUE LONG heap_idx_address

PROCEDURE heap_set_data PROTOTYPE
   PARAMETERS VALUE LONG heap_header, VALUE UINT heap_index, VALUE LONG data_ptr

FUNCTION LONG heap_get_data PROTOTYPE
   PARAMETERS VALUE LONG heap_header, VALUE UINT heap_index

PROCEDURE heap_sort PROTOTYPE
   PARAMETERS VALUE LONG heap_header

#ifndef HEAP_APPLY_PRG
FUNCTION LOGICAL heap_apply PROTOTYPE
   PARAMETERS VALUE LONG heap_header, UNTYPED function_pointer
#endif
*-------------------------------------------------------------------------
PROCEDURE heap_set_heap PROTOTYPE
   PARAMETERS VALUE LONG heap, VALUE LONG heap_ptr

PROCEDURE heap_set_size PROTOTYPE
   PARAMETERS VALUE LONG heap_size, VALUE UINT hsize

PROCEDURE heap_set_nodes PROTOTYPE
   PARAMETERS VALUE LONG nodes, VALUE UINT num_nodes

PROCEDURE heap_set_cmp PROTOTYPE
   PARAMETERS VALUE LONG cmp_addr, VALUE LONG cmp_ptr

FUNCTION LONG heap_get_heap PROTOTYPE
   PARAMETERS VALUE LONG heap_ptr

FUNCTION INT heap_get_nodes PROTOTYPE
   PARAMETERS VALUE LONG node_address

FUNCTION INT heap_get_size PROTOTYPE
   PARAMETERS VALUE LONG size_address

FUNCTION LONG heap_get_cmp PROTOTYPE
   PARAMETERS VALUE LONG cmp_address
*-------------------------------------------------------------------------
PROCEDURE set2_ptr PROTOTYPE
   PARAMETERS VALUE LONG ptr, VALUE LONG ptr2aptr

PROCEDURE swap_ptrs PROTOTYPE
   PARAMETERS VALUE LONG node_addr1, VALUE LONG node_addr2

*-------------------------------------------------------------------------
FUNCTION LOGICAL runfunc1 PROTOTYPE
   PARAMETERS VALUE LONG func_address, VALUE LONG ptr

FUNCTION INT runfunc2 PROTOTYPE
   PARAMETERS VALUE LONG func_address, VALUE LONG ptr1, VALUE LONG ptr2

PROCEDURE charcpy PROTOTYPE
   PARAMETERS VALUE LONG dest_address, CHAR source

PROCEDURE memncpy PROTOTYPE
   PARAMETERS VALUE LONG dest_address, VALUE LONG source_address, VALUE INT length

#endif   && if defined( HEAP_TOOLS )
*-------------------------------------------------------------------------
* Definitions....
*-------------------------------------------------------------------------
#define HEAP_HEADER_SIZE   12
*---
* The following are offsets into the heap structure
*---
#define HEAP_SIZE_OFFSET    0    && heap size is 2 bytes
#define HEAP_NODES_OFFSET   2    && number of nodes is 2 bytes
#define HEAP_CMP_OFFSET     4    && compare function ptr is 4 bytes
#define HEAP_HEAP_OFFSET    8    && heap pointer is 4 bytes

#ifndef TRUE
#define TRUE      .t.
#endif

#ifndef FALSE
#define FALSE     .f.
#endif

#define HEAP_INCREM  1024        && allocate 1K at a time...
#endif                           && HEAP_HDR


See Also: alloc.hdr
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson