ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/include/balloc.h
Revision: 33
Committed: Sun Oct 2 20:50:00 2005 UTC (18 years, 6 months ago) by knight
Content type: text/x-chdr
Original Path: ircd-hybrid/include/balloc.h
File size: 3066 byte(s)
Log Message:
- svn:keywords

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     *
4     * Copyright (C) 2002 by the past and present ircd coders, and others.
5     *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * USA
20     */
21    
22     /*! \file balloc.h
23     * \brief A block allocator
24 knight 31 * \version $Id$
25 adx 30 * \todo Get rid of all typedefs in this file
26     */
27    
28     #ifndef INCLUDED_balloc_h
29     #define INCLUDED_balloc_h
30    
31     #include "setup.h"
32    
33     #ifndef NOBALLOC
34     #include "client.h"
35     #include "tools.h"
36     #include "memory.h"
37     #include "ircd_defs.h"
38    
39    
40     /*! \brief Block contains status information for
41     * an allocated block in our heap.
42     */
43     struct Block {
44     int freeElems; /*!< Number of available elems */
45     size_t alloc_size; /*!< Size of data space for each block */
46     struct Block* next; /*!< Next in our chain of blocks */
47     void* elems; /*!< Points to allocated memory */
48     dlink_list free_list; /*!< Chain of free memory blocks */
49     dlink_list used_list; /*!< Chain of used memory blocks */
50     };
51    
52     typedef struct Block Block;
53    
54     struct MemBlock {
55     dlink_node self; /*!< Node for linking into free_list or used_list */
56     Block *block; /*!< Which block we belong to */
57     };
58     typedef struct MemBlock MemBlock;
59    
60     /*! \brief BlockHeap contains the information for the root node of the
61     * memory heap.
62     */
63     struct BlockHeap {
64     size_t elemSize; /*!< Size of each element to be stored */
65     int elemsPerBlock; /*!< Number of elements per block */
66     int blocksAllocated; /*!< Number of blocks allocated */
67     int freeElems; /*!< Number of free elements */
68     Block* base; /*!< Pointer to first block */
69     const char *name; /*!< Name of the heap */
70     struct BlockHeap *next; /*!< Pointer to next heap */
71     };
72    
73     typedef struct BlockHeap BlockHeap;
74    
75    
76     extern int BlockHeapFree(BlockHeap *, void *);
77     extern void * BlockHeapAlloc(BlockHeap *);
78    
79     extern BlockHeap* BlockHeapCreate(const char *const, size_t, int);
80     extern int BlockHeapDestroy(BlockHeap *);
81     extern void initBlockHeap(void);
82     extern void block_heap_report_stats(struct Client *);
83     #else /* NOBALLOC */
84    
85     typedef struct BlockHeap BlockHeap;
86     /* This is really kludgy, passing ints as pointers is always bad. */
87     #define BlockHeapCreate(blah, es, epb) ((BlockHeap*)(es))
88     #define BlockHeapAlloc(x) MyMalloc((int)x)
89     #define BlockHeapFree(x,y) MyFree(y)
90     #endif /* NOBALLOC */
91     #endif /* INCLUDED_balloc_h */

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision