3 /*-------------------------------------------------------------------------
4 * drawElements Memory Pool Library
5 * --------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Memory pool management.
24 *//*--------------------------------------------------------------------*/
28 #if defined(DE_DEV_BUILD)
29 /** Enable support for failure-simulating pool allocations. */
30 # define DE_SUPPORT_FAILING_POOL_ALLOC
32 /** Enable support for debug pools, which directly pass all allocations to deMalloc(). */
33 # define DE_SUPPORT_DEBUG_POOLS
35 /** Enable support for memory tracking of pools (will collect the maximum memory consumption to root pool). */
36 # define DE_SUPPORT_POOL_MEMORY_TRACKING
37 #endif /* DE_DEV_BUILD */
39 typedef enum deMemPoolFlag_e
41 DE_MEMPOOL_ENABLE_FAILING_ALLOCS = (1<<0),
42 DE_MEMPOOL_ENABLE_DEBUG_ALLOCS = (1<<1)
47 DE_POOL_DEFAULT_ALLOC_ALIGNMENT = DE_PTR_SIZE /*!< Default alignment for pool allocations (in bytes). */
50 /** Macro for allocating a new struct from a pool (leaves it uninitialized!). */
51 #define DE_POOL_NEW(POOL, TYPE) ((TYPE*)deMemPool_alloc(POOL, sizeof(TYPE)))
53 typedef void (*deMemPoolAllocFailFunc) (void* userPtr);
55 typedef struct deMemPoolUtil_s
58 deMemPoolAllocFailFunc allocFailCallback;
61 typedef struct deMemPool_s deMemPool;
65 deMemPool* deMemPool_createRoot (const deMemPoolUtil* util, deUint32 flags);
66 deMemPool* deMemPool_create (deMemPool* parent);
67 void deMemPool_destroy (deMemPool* pool);
68 int deMemPool_getNumChildren (const deMemPool* pool);
69 int deMemPool_getNumAllocatedBytes (const deMemPool* pool, deBool recurse);
70 int deMemPool_getCapacity (const deMemPool* pool, deBool recurse);
72 void* deMemPool_alloc (deMemPool* pool, size_t numBytes);
73 void* deMemPool_alignedAlloc (deMemPool* pool, size_t numBytes, deUint32 alignBytes);
74 void* deMemPool_memDup (deMemPool* pool, const void* ptr, size_t numBytes);
75 char* deMemPool_strDup (deMemPool* pool, const char* str);
76 char* deMemPool_strnDup (deMemPool* pool, const char* str, int maxLength);
78 #if defined(DE_SUPPORT_POOL_MEMORY_TRACKING)
79 int deMemPool_getMaxNumAllocatedBytes (const deMemPool* pool);
80 int deMemPool_getMaxCapacity (const deMemPool* pool);
85 #endif /* _DEMEMPOOL_H */