1 /* Functions to support a pool of allocatable objects 2 Copyright (C) 1997-2013 Free Software Foundation, Inc. 3 Contributed by Daniel Berlin <dan@cgsoftware.com> 4 5 This file is part of GCC. 6 7 GCC is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3, or (at your option) 10 any later version. 11 12 GCC is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with GCC; see the file COPYING3. If not see 19 <http://www.gnu.org/licenses/>. */ 20 #ifndef ALLOC_POOL_H 21 #define ALLOC_POOL_H 22 23 typedef unsigned long ALLOC_POOL_ID_TYPE; 24 25 typedef struct alloc_pool_list_def 26 { 27 struct alloc_pool_list_def *next; 28 } 29 *alloc_pool_list; 30 31 typedef struct alloc_pool_def 32 { 33 const char *name; 34 #ifdef ENABLE_CHECKING 35 ALLOC_POOL_ID_TYPE id; 36 #endif 37 size_t elts_per_block; 38 39 /* These are the elements that have been allocated at least once and freed. */ 40 alloc_pool_list returned_free_list; 41 42 /* These are the elements that have not yet been allocated out of 43 the last block obtained from XNEWVEC. */ 44 char* virgin_free_list; 45 46 /* The number of elements in the virgin_free_list that can be 47 allocated before needing another block. */ 48 size_t virgin_elts_remaining; 49 50 size_t elts_allocated; 51 size_t elts_free; 52 size_t blocks_allocated; 53 alloc_pool_list block_list; 54 size_t block_size; 55 size_t elt_size; 56 } 57 *alloc_pool; 58 59 extern alloc_pool create_alloc_pool (const char *, size_t, size_t); 60 extern void free_alloc_pool (alloc_pool); 61 extern void empty_alloc_pool (alloc_pool); 62 extern void free_alloc_pool_if_empty (alloc_pool *); 63 extern void *pool_alloc (alloc_pool) ATTRIBUTE_MALLOC; 64 extern void pool_free (alloc_pool, void *); 65 extern void dump_alloc_pool_statistics (void); 66 #endif 67