blob: 7e997888b51b6e5fc8eae41543fb85c3eead7e16 (
plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
*
* Copyright (C) 2002 by the past and present ircd coders, and others.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
/*! \file balloc.h
* \brief A block allocator
* \version $Id$
* \todo Get rid of all typedefs in this file
*/
#ifndef INCLUDED_balloc_h
#define INCLUDED_balloc_h
#include "config.h"
#include "client.h"
#include "ircd_defs.h"
/*! \brief Block contains status information for
* an allocated block in our heap.
*/
struct Block
{
int freeElems; /*!< Number of available elems */
size_t alloc_size; /*!< Size of data space for each block */
struct Block* next; /*!< Next in our chain of blocks */
void* elems; /*!< Points to allocated memory */
dlink_list free_list; /*!< Chain of free memory blocks */
};
typedef struct Block Block;
struct MemBlock
{
dlink_node self; /*!< Node for linking into free_list */
Block *block; /*!< Which block we belong to */
};
typedef struct MemBlock MemBlock;
/*! \brief BlockHeap contains the information for the root node of the
* memory heap.
*/
struct BlockHeap
{
size_t elemSize; /*!< Size of each element to be stored */
int elemsPerBlock; /*!< Number of elements per block */
int blocksAllocated; /*!< Number of blocks allocated */
int freeElems; /*!< Number of free elements */
Block* base; /*!< Pointer to first block */
const char *name; /*!< Name of the heap */
struct BlockHeap *next; /*!< Pointer to next heap */
};
typedef struct BlockHeap BlockHeap;
extern int BlockHeapFree(BlockHeap *, void *);
extern void * BlockHeapAlloc(BlockHeap *);
extern BlockHeap* BlockHeapCreate(const char *const, size_t, int);
extern int BlockHeapDestroy(BlockHeap *);
extern void initBlockHeap(void);
extern void block_heap_report_stats(struct Client *);
#endif /* INCLUDED_balloc_h */
|