alloc-pool.h 2.0 KB

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