ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/libio/mem/balloc.h
Revision: 62
Committed: Mon Oct 3 22:23:39 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-chdr
Original Path: ircd-hybrid/include/balloc.h
File size: 3369 byte(s)
Log Message:
- reorganisation goes on, removed external references from libio/mem

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 "tools.h"
35     #include "memory.h"
36    
37    
38     /*! \brief Block contains status information for
39     * an allocated block in our heap.
40     */
41     struct Block {
42     int freeElems; /*!< Number of available elems */
43     size_t alloc_size; /*!< Size of data space for each block */
44     struct Block* next; /*!< Next in our chain of blocks */
45     void* elems; /*!< Points to allocated memory */
46     dlink_list free_list; /*!< Chain of free memory blocks */
47     dlink_list used_list; /*!< Chain of used memory blocks */
48     };
49    
50     typedef struct Block Block;
51    
52     struct MemBlock {
53     dlink_node self; /*!< Node for linking into free_list or used_list */
54     Block *block; /*!< Which block we belong to */
55     };
56     typedef struct MemBlock MemBlock;
57    
58     /*! \brief BlockHeap contains the information for the root node of the
59     * memory heap.
60     */
61     struct BlockHeap {
62     size_t elemSize; /*!< Size of each element to be stored */
63     int elemsPerBlock; /*!< Number of elements per block */
64     int blocksAllocated; /*!< Number of blocks allocated */
65     int freeElems; /*!< Number of free elements */
66     Block* base; /*!< Pointer to first block */
67     const char *name; /*!< Name of the heap */
68     struct BlockHeap *next; /*!< Pointer to next heap */
69     };
70    
71     typedef struct BlockHeap BlockHeap;
72    
73    
74     extern int BlockHeapFree(BlockHeap *, void *);
75     extern void * BlockHeapAlloc(BlockHeap *);
76    
77     extern BlockHeap* BlockHeapCreate(const char *const, size_t, int);
78     extern int BlockHeapDestroy(BlockHeap *);
79     extern void initBlockHeap(void);
80 adx 62
81     extern size_t block_heap_get_used_mem(const BlockHeap *);
82     extern size_t block_heap_get_free_mem(const BlockHeap *);
83     extern size_t block_heap_get_size_mem(const BlockHeap *);
84     extern unsigned int block_heap_get_used_elm(const BlockHeap *);
85     extern unsigned int block_heap_get_free_elm(const BlockHeap *);
86     extern unsigned int block_heap_get_size_elm(const BlockHeap *);
87    
88 adx 30 #else /* NOBALLOC */
89    
90     typedef struct BlockHeap BlockHeap;
91     /* This is really kludgy, passing ints as pointers is always bad. */
92     #define BlockHeapCreate(blah, es, epb) ((BlockHeap*)(es))
93     #define BlockHeapAlloc(x) MyMalloc((int)x)
94     #define BlockHeapFree(x,y) MyFree(y)
95 adx 62
96 adx 30 #endif /* NOBALLOC */
97 adx 62
98     extern BlockHeap *heap_list;
99    
100 adx 30 #endif /* INCLUDED_balloc_h */

Properties

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