Lines Matching refs:pool

1 /* Functions to support a pool of allocatable objects.
25 #include "alloc-pool.h"
34 /* The ID of alloc pool which the object was allocated from. */
116 /* Create a pool of things of size SIZE, with NUM in each block we
122 alloc_pool pool;
145 /* Find the size of the pool structure, and the name. */
149 pool = xmalloc (pool_size);
151 /* Now init the various pieces of our pool structure. */
152 pool->name = /*xstrdup (name)*/name;
157 pool->elt_size = size;
158 pool->elts_per_block = num;
163 pool->block_size = (size * num) + header_size;
164 pool->free_list = NULL;
165 pool->elts_allocated = 0;
166 pool->elts_free = 0;
167 pool->blocks_allocated = 0;
168 pool->block_list = NULL;
171 /* Increase the last used ID and use it for this pool.
172 ID == 0 is used for free elements of pool so skip it. */
177 pool->id = last_id;
180 return (pool);
183 /* Free all memory allocated for the given memory pool. */
185 free_alloc_pool (alloc_pool pool)
189 struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name);
192 gcc_assert (pool);
194 /* Free each block allocated to the pool. */
195 for (block = pool->block_list; block != NULL; block = next_block)
200 desc->current -= pool->block_size;
204 memset (pool, 0xaf, sizeof (*pool));
206 /* Lastly, free the pool. */
207 free (pool);
212 free_alloc_pool_if_empty (alloc_pool *pool)
214 if ((*pool)->elts_free == (*pool)->elts_allocated)
216 free_alloc_pool (*pool);
217 *pool = NULL;
221 /* Allocates one element from the pool specified. */
223 pool_alloc (alloc_pool pool)
228 struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name);
230 desc->allocated+=pool->elt_size;
233 gcc_assert (pool);
236 if (!pool->free_list)
242 block = XNEWVEC (char, pool->block_size);
246 desc->current += pool->block_size;
252 block_header->next = pool->block_list;
253 pool->block_list = block_header;
256 for (i = 0; i < pool->elts_per_block; i++, block += pool->elt_size)
263 header->next = pool->free_list;
264 pool->free_list = header;
268 pool->elts_allocated += pool->elts_per_block;
269 pool->elts_free += pool->elts_per_block;
270 pool->blocks_allocated += 1;
274 header = pool->free_list;
275 pool->free_list = header->next;
276 pool->elts_free--;
280 ALLOCATION_OBJECT_PTR_FROM_USER_PTR (header)->id = pool->id;
288 pool_free (alloc_pool pool, void *ptr)
295 memset (ptr, 0xaf, pool->elt_size - offsetof (allocation_object, u.data));
298 gcc_assert (pool->id == ALLOCATION_OBJECT_PTR_FROM_USER_PTR (ptr)->id);
304 gcc_assert (pool->elts_free < pool->elts_allocated);
308 header->next = pool->free_list;
309 pool->free_list = header;
310 pool->elts_free++;
351 fprintf (stderr, "\nAlloc-pool Kind Pools Allocated Peak Leak\n");