Revision 5cc1e1f8 lib/mempool.c

View differences:

lib/mempool.c
1 1
/*
2 2
 *	BIRD Resource Manager -- Memory Pools
3 3
 *
4
 *	(c) 1998--1999 Martin Mares <mj@ucw.cz>
4
 *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
5 5
 *
6 6
 *	Can be freely distributed and used under the terms of the GNU GPL.
7 7
 */
8 8

  
9
/**
10
 * DOC: Linear memory pools
11
 *
12
 * Linear memory pools are collections of memory blocks which
13
 * support very fast allocation of new blocks, but are able to free only
14
 * the whole collection at once.
15
 *
16
 * Example: Each configuration is described by a complex system of structures,
17
 * linked lists and function trees which are all allocated from a single linear
18
 * pool, thus they can be freed at once when the configuration is no longer used.
19
 */
20

  
9 21
#include <stdlib.h>
10 22

  
11 23
#include "nest/bird.h"
......
38 50
  lp_lookup
39 51
};
40 52

  
53
/**
54
 * lp_new - create a new linear memory pool
55
 * @p: pool
56
 * @blk: block size
57
 *
58
 * lp_new() creates a new linear memory pool resource inside the pool @p.
59
 * The linear pool consists of a list of memory chunks of size at least
60
 * @blk.
61
 */
41 62
linpool
42 63
*lp_new(pool *p, unsigned blk)
43 64
{
......
52 73
  return m;
53 74
}
54 75

  
76
/**
77
 * lp_alloc - allocate memory from a &linpool
78
 * @m: linear memory pool
79
 * @size: amount of memory
80
 *
81
 * lp_alloc() allocates @size bytes of memory from a &linpool @m
82
 * and it returns a pointer to the allocated memory.
83
 *
84
 * It works by trying to find free space in the last memory chunk
85
 * associated with the &linpool and creating a new chunk of the standard
86
 * size (as specified during lp_new()) if the free space is too small
87
 * to satisfy the allocation. If @size is too large to fit in a standard
88
 * size chunk, an "overflow" chunk is created for it instead.
89
 */
55 90
void *
56 91
lp_alloc(linpool *m, unsigned size)
57 92
{
......
100 135
    }
101 136
}
102 137

  
138
/**
139
 * lp_allocu - allocate unaligned memory from a &linpool
140
 * @m: linear memory pool
141
 * @size: amount of memory
142
 *
143
 * lp_allocu() allocates @size bytes of memory from a &linpool @m
144
 * and it returns a pointer to the allocated memory. It doesn't
145
 * attempt to align the memory block, giving a very efficient way
146
 * how to allocate strings without any space overhead.
147
 */
103 148
void *
104 149
lp_allocu(linpool *m, unsigned size)
105 150
{
......
114 159
  return lp_alloc(m, size);
115 160
}
116 161

  
162
/**
163
 * lp_allocz - allocate cleared memory from a &linpool
164
 * @m: linear memory pool
165
 * @size: amount of memory
166
 *
167
 * This function is identical to lp_alloc() except that it
168
 * clears the allocated memory block.
169
 */
117 170
void *
118 171
lp_allocz(linpool *m, unsigned size)
119 172
{
......
123 176
  return z;
124 177
}
125 178

  
179
/**
180
 * lp_flush - flush a linear memory pool
181
 * @m: linear memory pool
182
 *
183
 * This function frees the whole contents of the given &linpool @m,
184
 * but leaves the pool itself.
185
 */
126 186
void
127 187
lp_flush(linpool *m)
128 188
{

Also available in: Unified diff