#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 _FixHeap * | FixHeapPtr |
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) |
|
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) |
|
use this to compute reasonable malloc chunk sizes |
|
|
|
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. |
|
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. |
|
|
|
|
|
|
|
|