From 419f2d6236f6a4d83ccaf82a14610bfe532065e6 Mon Sep 17 00:00:00 2001 From: marxin Date: Mon, 1 Jun 2015 12:29:12 +0000 Subject: Introduce new type-based pool allocator. * alloc-pool.c (struct alloc_pool_descriptor): Move definition to header file. * alloc-pool.h (pool_allocator::pool_allocator): New function. (pool_allocator::release): Likewise. (inline pool_allocator::release_if_empty): Likewise. (inline pool_allocator::~pool_allocator): Likewise. (pool_allocator::allocate): Likewise. (pool_allocator::remove): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@223942 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/alloc-pool.c | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) (limited to 'gcc/alloc-pool.c') diff --git a/gcc/alloc-pool.c b/gcc/alloc-pool.c index e34acdb3500..829556fe25a 100644 --- a/gcc/alloc-pool.c +++ b/gcc/alloc-pool.c @@ -25,6 +25,8 @@ along with GCC; see the file COPYING3. If not see #include "hash-table.h" #include "hash-map.h" +ALLOC_POOL_ID_TYPE last_id; + #define align_eight(x) (((x+7) >> 3) << 3) /* The internal allocation object. */ @@ -58,36 +60,10 @@ typedef struct allocation_object_def #define USER_PTR_FROM_ALLOCATION_OBJECT_PTR(X) \ ((void *) (((allocation_object *) (X))->u.data)) -#ifdef ENABLE_CHECKING -/* Last used ID. */ -static ALLOC_POOL_ID_TYPE last_id; -#endif - -/* Store information about each particular alloc_pool. Note that this - will underestimate the amount the amount of storage used by a small amount: - 1) The overhead in a pool is not accounted for. - 2) The unallocated elements in a block are not accounted for. Note - that this can at worst case be one element smaller that the block - size for that pool. */ -struct alloc_pool_descriptor -{ - /* Number of pools allocated. */ - unsigned long created; - /* Gross allocated storage. */ - unsigned long allocated; - /* Amount of currently active storage. */ - unsigned long current; - /* Peak amount of storage used. */ - unsigned long peak; - /* Size of element in the pool. */ - int elt_size; -}; - /* Hashtable mapping alloc_pool names to descriptors. */ -static hash_map *alloc_pool_hash; +hash_map *alloc_pool_hash; -/* For given name, return descriptor, create new if needed. */ -static struct alloc_pool_descriptor * +struct alloc_pool_descriptor * allocate_pool_descriptor (const char *name) { if (!alloc_pool_hash) @@ -98,6 +74,7 @@ allocate_pool_descriptor (const char *name) return &alloc_pool_hash->get_or_insert (name); } + /* Create a pool of things of size SIZE, with NUM in each block we allocate. */ -- cgit v1.2.1