Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/mempool-alloconly.c @ 903:fd8888f6f037 HEAD
Naming style changes, finally got tired of most of the typedefs. Also the
previous enum -> macro change reverted so that we don't use the highest bit
anymore, that's incompatible with old indexes so they will be rebuilt.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 05 Jan 2003 15:09:51 +0200 |
parents | 3d437b1e5257 |
children | 4d6b69558add |
rev | line source |
---|---|
0 | 1 /* |
2 mempool-alloconly.c : Memory pool for fast allocation of memory without | |
3 need to free it in small blocks | |
4 | |
5 Copyright (c) 2002 Timo Sirainen | |
6 | |
7 Permission is hereby granted, free of charge, to any person obtaining | |
8 a copy of this software and associated documentation files (the | |
9 "Software"), to deal in the Software without restriction, including | |
10 without limitation the rights to use, copy, modify, merge, publish, | |
11 distribute, sublicense, and/or sell copies of the Software, and to | |
12 permit persons to whom the Software is furnished to do so, subject to | |
13 the following conditions: | |
14 | |
15 The above copyright notice and this permission notice shall be | |
16 included in all copies or substantial portions of the Software. | |
17 | |
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
21 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
22 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
23 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
24 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
25 */ | |
26 | |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
699
diff
changeset
|
27 /* @UNSAFE: whole file */ |
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
699
diff
changeset
|
28 |
0 | 29 #include "lib.h" |
30 #include "mempool.h" | |
31 | |
32 #include <stdlib.h> | |
33 | |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
72
diff
changeset
|
34 #define MAX_ALLOC_SIZE SSIZE_T_MAX |
0 | 35 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
36 struct alloconly_pool { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
37 struct pool pool; |
0 | 38 int refcount; |
39 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
40 struct pool_block *block; |
0 | 41 |
42 char name[MEM_ALIGN_SIZE]; /* variable size */ | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
43 }; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
44 #define SIZEOF_ALLOCONLYPOOL (sizeof(struct alloconly_pool)-MEM_ALIGN_SIZE) |
0 | 45 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
46 struct pool_block { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
47 struct pool_block *prev; |
0 | 48 |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
72
diff
changeset
|
49 size_t size; |
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
72
diff
changeset
|
50 size_t left; |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
51 size_t last_alloc_size; |
0 | 52 |
72 | 53 /* unsigned char data[]; */ |
0 | 54 }; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
55 #define SIZEOF_POOLBLOCK (MEM_ALIGN(sizeof(struct pool_block))) |
72 | 56 |
57 #define POOL_BLOCK_DATA(block) \ | |
58 ((char *) (block) + SIZEOF_POOLBLOCK) | |
0 | 59 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
60 struct pool_alloc { |
67
b28ac4106d5a
Allocated memory wasn't aligned according to MEM_ALIGN_SIZE.
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
61 union { |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
72
diff
changeset
|
62 size_t size; |
67
b28ac4106d5a
Allocated memory wasn't aligned according to MEM_ALIGN_SIZE.
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
63 unsigned char alignment[MEM_ALIGN_SIZE]; |
b28ac4106d5a
Allocated memory wasn't aligned according to MEM_ALIGN_SIZE.
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
64 } size; |
0 | 65 unsigned char data[MEM_ALIGN_SIZE]; /* variable size */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
66 }; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
67 #define SIZEOF_POOLALLOC (sizeof(struct pool_alloc)-MEM_ALIGN_SIZE) |
0 | 68 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
69 static void pool_alloconly_ref(pool_t pool); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
70 static void pool_alloconly_unref(pool_t pool); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
71 static void *pool_alloconly_malloc(pool_t pool, size_t size); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
72 static void pool_alloconly_free(pool_t pool, void *mem); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
73 static void *pool_alloconly_realloc(pool_t pool, void *mem, size_t size); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
74 static void pool_alloconly_clear(pool_t pool); |
0 | 75 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
76 static void block_alloc(struct alloconly_pool *pool, size_t size); |
330 | 77 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
78 static struct pool static_alloconly_pool = { |
330 | 79 pool_alloconly_ref, |
80 pool_alloconly_unref, | |
81 | |
82 pool_alloconly_malloc, | |
83 pool_alloconly_free, | |
84 | |
85 pool_alloconly_realloc, | |
86 | |
87 pool_alloconly_clear | |
88 }; | |
0 | 89 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
90 pool_t pool_alloconly_create(const char *name, size_t size) |
0 | 91 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
92 struct alloconly_pool *apool; |
0 | 93 int len; |
94 | |
95 len = strlen(name); | |
96 | |
97 apool = calloc(SIZEOF_ALLOCONLYPOOL + len+1, 1); | |
409
849f3846212a
Check return values for malloc()s and calloc()s.
Timo Sirainen <tss@iki.fi>
parents:
330
diff
changeset
|
98 if (apool == NULL) |
849f3846212a
Check return values for malloc()s and calloc()s.
Timo Sirainen <tss@iki.fi>
parents:
330
diff
changeset
|
99 i_panic("pool_alloconly_create(): Out of memory"); |
0 | 100 apool->pool = static_alloconly_pool; |
101 apool->refcount = 1; | |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
102 memcpy(apool->name, name, len+1); |
0 | 103 |
104 block_alloc(apool, size); | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
105 return (struct pool *) apool; |
0 | 106 } |
107 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
108 static void pool_alloconly_destroy(struct alloconly_pool *apool) |
0 | 109 { |
110 /* destroy all but the last block */ | |
111 pool_alloconly_clear(&apool->pool); | |
112 | |
113 /* destroy the last block */ | |
114 free(apool->block); | |
115 free(apool); | |
116 } | |
117 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
118 static void pool_alloconly_ref(pool_t pool) |
0 | 119 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
120 struct alloconly_pool *apool = (struct alloconly_pool *) pool; |
0 | 121 |
122 apool->refcount++; | |
123 } | |
124 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
125 static void pool_alloconly_unref(pool_t pool) |
0 | 126 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
127 struct alloconly_pool *apool = (struct alloconly_pool *) pool; |
0 | 128 |
129 if (--apool->refcount == 0) | |
130 pool_alloconly_destroy(apool); | |
131 } | |
132 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
133 static void block_alloc(struct alloconly_pool *apool, size_t size) |
0 | 134 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
135 struct pool_block *block; |
0 | 136 |
137 /* each block is at least twice the size of the previous one */ | |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
138 if (apool->block != NULL && size <= apool->block->size) |
0 | 139 size += apool->block->size; |
140 | |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
141 size = nearest_power(size + SIZEOF_POOLBLOCK); |
0 | 142 |
826 | 143 #ifdef DEBUG |
144 if (apool->block != NULL) { | |
145 i_warning("Growing pool '%s' with: %"PRIuSIZE_T, | |
146 apool->name, size); | |
147 } | |
148 #endif | |
149 | |
0 | 150 block = calloc(size, 1); |
409
849f3846212a
Check return values for malloc()s and calloc()s.
Timo Sirainen <tss@iki.fi>
parents:
330
diff
changeset
|
151 if (block == NULL) |
849f3846212a
Check return values for malloc()s and calloc()s.
Timo Sirainen <tss@iki.fi>
parents:
330
diff
changeset
|
152 i_panic("block_alloc(): Out of memory"); |
0 | 153 block->prev = apool->block; |
154 apool->block = block; | |
155 | |
156 block->size = size - SIZEOF_POOLBLOCK; | |
157 block->left = block->size; | |
158 } | |
159 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
160 static void *pool_alloconly_malloc(pool_t pool, size_t size) |
0 | 161 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
162 struct alloconly_pool *apool = (struct alloconly_pool *) pool; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
163 struct pool_alloc *alloc; |
0 | 164 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
826
diff
changeset
|
165 if (size == 0 || size > SSIZE_T_MAX) |
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
826
diff
changeset
|
166 i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size); |
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
826
diff
changeset
|
167 |
0 | 168 size = MEM_ALIGN(size); |
169 | |
170 if (apool->block->left < size + SIZEOF_POOLALLOC) { | |
171 /* we need a new block */ | |
172 block_alloc(apool, size); | |
173 } | |
174 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
175 alloc = (struct pool_alloc *) (POOL_BLOCK_DATA(apool->block) + |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
176 apool->block->size - apool->block->left); |
67
b28ac4106d5a
Allocated memory wasn't aligned according to MEM_ALIGN_SIZE.
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
177 alloc->size.size = size; |
0 | 178 |
179 apool->block->left -= size + SIZEOF_POOLALLOC; | |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
180 apool->block->last_alloc_size = size; |
0 | 181 return alloc->data; |
182 } | |
183 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
184 static void pool_alloconly_free(pool_t pool __attr_unused__, |
0 | 185 void *mem __attr_unused__) |
186 { | |
187 /* ignore */ | |
188 } | |
189 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
190 static int pool_try_grow(struct alloconly_pool *apool, void *mem, size_t size) |
0 | 191 { |
192 /* see if we want to grow the memory we allocated last */ | |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
193 if (POOL_BLOCK_DATA(apool->block) + |
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
194 (apool->block->size - apool->block->left - |
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
195 apool->block->last_alloc_size) == mem) { |
0 | 196 /* yeah, see if we can grow */ |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
197 if (apool->block->left >= size-apool->block->last_alloc_size) { |
0 | 198 /* just shrink the available size */ |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
199 apool->block->left -= |
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
200 size - apool->block->last_alloc_size; |
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
201 apool->block->last_alloc_size = size; |
0 | 202 return TRUE; |
203 } | |
204 } | |
205 | |
206 return FALSE; | |
207 } | |
208 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
209 static void *pool_alloconly_realloc(pool_t pool, void *mem, size_t size) |
0 | 210 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
211 struct alloconly_pool *apool = (struct alloconly_pool *) pool; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
212 struct pool_alloc *alloc; |
0 | 213 unsigned char *new_mem; |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
72
diff
changeset
|
214 size_t old_size; |
0 | 215 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
826
diff
changeset
|
216 if (size == 0 || size > SSIZE_T_MAX) |
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
826
diff
changeset
|
217 i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size); |
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
826
diff
changeset
|
218 |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
219 if (mem == NULL) |
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
220 return pool_alloconly_malloc(pool, size); |
0 | 221 |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
222 /* get old size */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
223 alloc = (struct pool_alloc *) ((char *) mem - SIZEOF_POOLALLOC); |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
224 old_size = alloc->size.size; |
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
225 |
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
226 if (size <= old_size) |
0 | 227 return mem; |
228 | |
229 size = MEM_ALIGN(size); | |
230 | |
231 /* see if we can directly grow it */ | |
422 | 232 if (!pool_try_grow(apool, mem, size)) { |
233 /* slow way - allocate + copy */ | |
234 new_mem = pool_alloconly_malloc(pool, size); | |
235 memcpy(new_mem, mem, old_size); | |
236 mem = new_mem; | |
237 } | |
0 | 238 |
239 if (size > old_size) { | |
240 /* clear new data */ | |
695 | 241 memset((char *) mem + old_size, 0, size - old_size); |
0 | 242 } |
243 | |
422 | 244 return mem; |
0 | 245 } |
246 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
247 static void pool_alloconly_clear(pool_t pool) |
0 | 248 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
249 struct alloconly_pool *apool = (struct alloconly_pool *) pool; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
857
diff
changeset
|
250 struct pool_block *block; |
0 | 251 |
252 /* destroy all blocks but the last, which is the largest */ | |
253 while (apool->block->prev != NULL) { | |
254 block = apool->block; | |
255 apool->block = block->prev; | |
256 | |
257 free(block); | |
258 } | |
259 | |
260 /* clear the last block */ | |
72 | 261 memset(POOL_BLOCK_DATA(apool->block), 0, |
262 apool->block->size - apool->block->left); | |
0 | 263 apool->block->left = apool->block->size; |
857
3d437b1e5257
Removed pool->realloc_min() which nothing used. A few small fixes to
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
264 apool->block->last_alloc_size = 0; |
0 | 265 } |