Main Page | Struct List | File List | Struct Members | File Members

fixheap.h File Reference

#include <stdio.h>

Go to the source code of this file.

Defines

#define MALLOC_OVERHEAD   64
#define FIXHEAP_OVERHEAD   32
#define COMPUTE_ALLOC_COUNT(kBytes, Type)   (((((kBytes)*1024)-MALLOC_OVERHEAD)-FIXHEAP_OVERHEAD)/sizeof(Type))

Typedefs

typedef _FixHeap FixHeap
typedef _FixHeapFixHeapPtr

Functions

FixHeapPtr FixHeapCreate (char *name, unsigned long nodeSize, unsigned long nodesPerAlloc, int verbose)
void FixHeapRelease (FixHeapPtr heap)
void * FixHeapMalloc (FixHeapPtr heap)
void FixHeapFree (FixHeapPtr heap, void *node)


Define Documentation

#define COMPUTE_ALLOC_COUNT kBytes,
Type   )     (((((kBytes)*1024)-MALLOC_OVERHEAD)-FIXHEAP_OVERHEAD)/sizeof(Type))
 

compute the number of nodes to allocate per heap expand, this is specified as the size (in kBytes) of each chunk allocated, for example, COMPUTE_ALLOC_COUNT(32, FooRec), will make the fix heap manager allocate as many FooRec's that fit into 32k each time it expands the heap, the fix heap manager knows about the overheads incurred by malloc operations (from machine.h) and fix heap management (FIXHEAP_OVERHEAD)

#define FIXHEAP_OVERHEAD   32
 

use this to compute reasonable malloc chunk sizes

#define MALLOC_OVERHEAD   64
 


Typedef Documentation

typedef struct _FixHeap FixHeap
 

fixed size node heap manager:

most fast Unix malloc packages allocate blocks in only sizes that are a power of 2 bytes; for a program that uses a LOT of small structures (like TETRA) this greatly increase memory usage; for example, a 38 byte structure will typically be allocated in a 64 byte block; the fixed node size heap manager allocates blocks in a large array, and then maintains a free list for this allocation, thus the system malloc overhead is only bore for a block of allocations, rather than for each; the other advantage of a fixed size allocator is better memory reference locality - since the overhead is moved away from the allocated nodes

do not use this for infrequently used nodes; to compute the nodesPerAlloc, use a variant of the following equation

nodesPerAlloc = floor((64k - sys_overhead - FixHeap_overhead)/nodeSize)

where: sys_overhead: is the system malloc overhead (always less 64 bytes on the DECstation's default malloc package), make this conservatively large! FixHeap_overhead: is the fixed head size manager's overhead, which is always less than 32 bytes

Increase or decrease the mass allocation size to match the usage of the particular node type.

typedef struct _FixHeap * FixHeapPtr
 

fixed size node heap manager:

most fast Unix malloc packages allocate blocks in only sizes that are a power of 2 bytes; for a program that uses a LOT of small structures (like TETRA) this greatly increase memory usage; for example, a 38 byte structure will typically be allocated in a 64 byte block; the fixed node size heap manager allocates blocks in a large array, and then maintains a free list for this allocation, thus the system malloc overhead is only bore for a block of allocations, rather than for each; the other advantage of a fixed size allocator is better memory reference locality - since the overhead is moved away from the allocated nodes

do not use this for infrequently used nodes; to compute the nodesPerAlloc, use a variant of the following equation

nodesPerAlloc = floor((64k - sys_overhead - FixHeap_overhead)/nodeSize)

where: sys_overhead: is the system malloc overhead (always less 64 bytes on the DECstation's default malloc package), make this conservatively large! FixHeap_overhead: is the fixed head size manager's overhead, which is always less than 32 bytes

Increase or decrease the mass allocation size to match the usage of the particular node type.


Function Documentation

FixHeapPtr FixHeapCreate char *  name,
unsigned long  nodeSize,
unsigned long  nodesPerAlloc,
int  verbose
 

void FixHeapFree FixHeapPtr  heap,
void *  node
 

void* FixHeapMalloc FixHeapPtr  heap  ) 
 

void FixHeapRelease FixHeapPtr  heap  ) 
 


Generated on Thu Jan 27 11:30:34 2005 for STACCATO_PROJECT by  doxygen 1.4.0