]>
jfr.im git - solanum.git/blob - libcharybdis/balloc.h
2 * ircd-ratbox: A slightly useful ircd.
3 * balloc.h: The ircd block allocator header.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2004 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: balloc.h 1781 2006-07-30 18:07:38Z jilles $
27 #ifndef INCLUDED_blalloc_h
28 #define INCLUDED_blalloc_h
33 #include "ircd_defs.h"
35 #define CACHEFILE_HEAP_SIZE 32
36 #define CACHELINE_HEAP_SIZE 64
41 typedef struct BlockHeap BlockHeap
;
42 #define initBlockHeap()
43 #define BlockHeapGarbageCollect(x)
44 #define BlockHeapCreate(es, epb) ((BlockHeap*)(es))
45 #define BlockHeapDestroy(x)
46 #define BlockHeapAlloc(x) MyMalloc((int)x)
47 #define BlockHeapFree(x,y) MyFree(y)
48 #define BlockHeapUsage(bh, bused, bfree, bmemusage) do { if (bused) (*(size_t *)bused) = 0; if (bfree) *((size_t *)bfree) = 0; if (bmemusage) *((size_t *)bmemusage) = 0; } while(0)
49 typedef struct MemBlock
59 #define BALLOC_MAGIC 0x3d3a3c3d
60 #define BALLOC_FREE_MAGIC 0xafafafaf
63 /* status information for an allocated block in heap */
67 struct Block
*next
; /* Next in our chain of blocks */
68 void *elems
; /* Points to allocated memory */
72 typedef struct Block Block
;
80 Block
*block
; /* Which block we belong to */
83 typedef struct MemBlock MemBlock
;
85 /* information for the root node of the heap */
89 size_t elemSize
; /* Size of each element to be stored */
90 unsigned long elemsPerBlock
; /* Number of elements per block */
91 unsigned long blocksAllocated
; /* Number of blocks allocated */
92 unsigned long freeElems
; /* Number of free elements */
93 Block
*base
; /* Pointer to first block */
95 typedef struct BlockHeap BlockHeap
;
97 extern int BlockHeapFree(BlockHeap
* bh
, void *ptr
);
98 extern void *BlockHeapAlloc(BlockHeap
* bh
);
100 extern BlockHeap
*BlockHeapCreate(size_t elemsize
, int elemsperblock
);
101 extern int BlockHeapDestroy(BlockHeap
* bh
);
103 extern void initBlockHeap(void);
104 extern void BlockHeapUsage(BlockHeap
* bh
, size_t * bused
, size_t * bfree
, size_t * bmemusage
);
108 #endif /* NOBALLOC */
112 #endif /* INCLUDED_blalloc_h */