1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "glslmemorypool.h"
39 MemoryPool::MemoryPool()
47 MemoryPool::~MemoryPool()
50 for (int i = 0; i < _allocatedBlocks; ++i) {
51 if (char *b = _blocks[i])
59 void MemoryPool::reset()
65 void *MemoryPool::allocate_helper(size_t size)
67 assert(size < BLOCK_SIZE);
69 if (++_blockCount == _allocatedBlocks) {
70 if (! _allocatedBlocks)
71 _allocatedBlocks = DEFAULT_BLOCK_COUNT;
73 _allocatedBlocks *= 2;
75 _blocks = (char **) realloc(_blocks, sizeof(char *) * _allocatedBlocks);
77 for (int index = _blockCount; index < _allocatedBlocks; ++index)
81 char *&block = _blocks[_blockCount];
84 block = (char *) std::malloc(BLOCK_SIZE);
87 _end = _ptr + BLOCK_SIZE;
94 RecursiveMemoryPool::RecursiveMemoryPool(MemoryPool *pool)
96 _blockCount(pool->_blockCount),
102 RecursiveMemoryPool::~RecursiveMemoryPool()
104 _pool->_blockCount = _blockCount;
115 void *Managed::operator new(size_t size, MemoryPool *pool)
116 { return pool->allocate(size); }
118 void Managed::operator delete(void *)
121 void Managed::operator delete(void *, MemoryPool *)