Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
array-impl.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the gobelijn software.
3  * Gobelijn is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the
5  * Free Software Foundation, either version 3 of the License, or any later
6  * version. Gobelijn is distributed in the hope that it will be useful, but
7  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8  * or FITNESS FOR A PARTICULAR PURPOSE.
9  * See the GNU General Public License for details. You should have received
10  * a copy of the GNU General Public License along with the software. If not,
11  * see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2016, Jan Broeckhove.
14  */
20 #include "MemoryPool.h"
21 
22 namespace Pimpl {
26 struct MemoryPool::MemoryPoolImpl
27 {
28  MemoryPoolImpl(char* string, int i) : pointer(string), allocatedCount(static_cast<size_t>(i)) {}
29  char* pointer;
30  size_t allocatedCount;
31 };
32 
36 MemoryPool::MemoryPool(size_t capacity) : m_impl(new MemoryPoolImpl(new char[capacity], 0)) {}
37 
42 {
43  // Erase the entire memory pool in one fell swoop.
44  delete[] m_impl->pointer;
45 }
46 
51 char* MemoryPool::AllocateMemory(size_t size)
52 {
53  // Allocate memory by incrementing a pointer.
54  char* result = m_impl->pointer + m_impl->allocatedCount;
55  m_impl->allocatedCount += size;
56  return result;
57 }
58 } // namespace Pimpl
~MemoryPool()
Frees this memory pool's resources, if any.
Definition: array-impl.cpp:41
std::unique_ptr< MemoryPoolImpl > m_impl
Fortunately, we don't need a definition to create a pointer to MemoryPoolImpl, so that's exactly what...
Definition: MemoryPool.h:60
Pimpl demo with memory pool.
char * AllocateMemory(size_t size)
Allocates a region of memory that is the given number of bytes in size.
Definition: array-impl.cpp:51