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