3 /*-------------------------------------------------------------------------
4 * drawElements C++ Base 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 (deMemPool wrapper).
24 *//*--------------------------------------------------------------------*/
27 #include "deMemPool.h"
34 /*--------------------------------------------------------------------*//*!
36 *//*--------------------------------------------------------------------*/
40 MemPool (const deMemPoolUtil* util = DE_NULL, deUint32 flags = 0u);
41 MemPool (MemPool* parent);
44 deMemPool* getRawPool (void) { return m_pool; }
46 int getNumChildren (void) const { return deMemPool_getNumChildren(m_pool); }
48 deUintptr getNumAllocatedBytes (bool recurse) const { return deMemPool_getNumAllocatedBytes(m_pool, recurse ? DE_TRUE : DE_FALSE); }
49 deUintptr getCapacity (bool recurse) const { return deMemPool_getCapacity(m_pool, recurse ? DE_TRUE : DE_FALSE); }
51 void* alloc (deUintptr numBytes);
52 void* alignedAlloc (deUintptr numBytes, deUint32 alignBytes);
55 MemPool (const MemPool& other); // Not allowed!
56 MemPool& operator= (const MemPool& other); // Not allowed!
63 char* copyToPool (de::MemPool* pool, const char* string);
65 // MemPool inline implementations.
67 inline MemPool::MemPool (const deMemPoolUtil* util, deUint32 flags)
69 m_pool = deMemPool_createRoot(util, flags);
71 throw std::bad_alloc();
74 inline MemPool::MemPool (MemPool* parent)
76 m_pool = deMemPool_create(parent->m_pool);
78 throw std::bad_alloc();
81 inline MemPool::~MemPool (void)
83 deMemPool_destroy(m_pool);
86 inline void* MemPool::alloc (deUintptr numBytes)
88 // \todo [2013-02-07 pyry] Use deUintptr in deMemPool.
89 DE_ASSERT((deUintptr)(int)numBytes == numBytes);
90 void* ptr = deMemPool_alloc(m_pool, (int)numBytes);
92 throw std::bad_alloc();
96 inline void* MemPool::alignedAlloc (deUintptr numBytes, deUint32 alignBytes)
98 // \todo [2013-02-07 pyry] Use deUintptr in deMemPool.
99 DE_ASSERT((deUintptr)(int)numBytes == numBytes);
100 void* ptr = deMemPool_alignedAlloc(m_pool, (int)numBytes, alignBytes);
102 throw std::bad_alloc();
108 #endif // _DEMEMPOOL_HPP