| 1 |
pippijn |
1.1 |
/* |
| 2 |
|
|
* Copyright © 2005 William Pitcock, et al. |
| 3 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 4 |
pippijn |
1.1 |
* |
| 5 |
|
|
* Data structures for the block allocator. |
| 6 |
|
|
* |
| 7 |
pippijn |
1.3 |
* $Id: balloc.h,v 1.2 2007-07-21 01:29:07 pippijn Exp $ |
| 8 |
pippijn |
1.1 |
*/ |
| 9 |
|
|
|
| 10 |
|
|
#ifndef BALLOC_H |
| 11 |
|
|
#define BALLOC_H |
| 12 |
|
|
|
| 13 |
|
|
struct Block |
| 14 |
|
|
{ |
| 15 |
|
|
size_t alloc_size; |
| 16 |
|
|
struct Block *next; /* Next in our chain of blocks */ |
| 17 |
|
|
void *elems; /* Points to allocated memory */ |
| 18 |
|
|
list_t free_list; |
| 19 |
|
|
list_t used_list; |
| 20 |
|
|
}; |
| 21 |
|
|
|
| 22 |
|
|
struct MemBlock |
| 23 |
|
|
{ |
| 24 |
|
|
#ifdef DEBUG_BALLOC |
| 25 |
|
|
unsigned long magic; |
| 26 |
|
|
#endif |
| 27 |
|
|
node_t self; |
| 28 |
|
|
Block *block; /* Which block we belong to */ |
| 29 |
|
|
}; |
| 30 |
|
|
|
| 31 |
|
|
/* information for the root node of the heap */ |
| 32 |
|
|
struct BlockHeap |
| 33 |
|
|
{ |
| 34 |
|
|
node_t hlist; |
| 35 |
|
|
size_t elemSize; /* Size of each element to be stored */ |
| 36 |
|
|
unsigned long elemsPerBlock; /* Number of elements per block */ |
| 37 |
|
|
unsigned long blocksAllocated; /* Number of blocks allocated */ |
| 38 |
|
|
unsigned long freeElems; /* Number of free elements */ |
| 39 |
|
|
Block *base; /* Pointer to first block */ |
| 40 |
|
|
}; |
| 41 |
|
|
|
| 42 |
|
|
E int BlockHeapFree (BlockHeap *bh, void *ptr); |
| 43 |
|
|
E void *BlockHeapAlloc (BlockHeap *bh); |
| 44 |
|
|
|
| 45 |
|
|
E BlockHeap *BlockHeapCreate (size_t elemsize, int elemsperblock); |
| 46 |
|
|
E int BlockHeapDestroy (BlockHeap *bh); |
| 47 |
|
|
|
| 48 |
|
|
E void initBlockHeap (void); |
| 49 |
|
|
E void BlockHeapUsage (BlockHeap *bh, size_t * bused, size_t * bfree, size_t * bmemusage); |
| 50 |
|
|
|
| 51 |
|
|
#endif |