ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/libio/mem/balloc.h
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-chdr
File size: 3224 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


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

Properties

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