File: blalloc.txt

package info (click to toggle)
dancer-ircd 1.0.36-8
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 3,204 kB
  • ctags: 2,703
  • sloc: ansic: 36,121; sh: 3,534; perl: 612; makefile: 307
file content (41 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
These routines form a robust, block allocation mechanism that is somewhat
tweakable for specific applications.

BlockHeap * BlockHeapCreate (size_t elemsize, int elemsperblock)

     Creates a new block heap, from which elements can be allocated.  The
     size of each block of memory can be tuned by changing elemsperblock.
     elemsize should contain the size of elements you will be allocating
     from this block.

void * BlockHeapAlloc (BlockHeap *bh)

     Allocates a single element from the passed block heap.  Be sure to
     cast the returned pointer to the type you expect.  Alternately,
     you can use the #defined macro BlockHeapALLOC (BlockHeap *bh, type)
     where "type" is your element type (int, double, struct, etc.)

int BlockHeapGarbageCollect (BlockHeap *bh)

     Cleans up all blocks that are completely free in the blockheap.
     Used as a general-purpose garbage collection routine.

int BlockHeapFree (BlockHeap *bh, void *ptr)

     Frees the element pointed to by *ptr.  The memory is not returned to
     the system -- just the block heap itself.  Returns 0 if successful, or
     1 if the element is not contained within the given blockheap.

int BlockHeapDestroy (BlockHeap *bh)

     Destroys the entire block heap, including free()ing all associated
     memory.  Use as a cleanup function; all pointers to memory allocated
     using BlockHeapAlloc() will become invalid.

------------------------------------------------------------------------

Note: do not use this system for anything new. The authors was
braindamaged; block allocation is stupid. It appears faster by sheer
coincidence.

 - asuffield