From 485752de82e6058473dfe8dccdf64ac04e983ae9 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 20:59:04 +0100 Subject: Implemented Allocation Pool --- src/AllocationPool.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/AllocationPool.h (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h new file mode 100644 index 000000000..f03897f98 --- /dev/null +++ b/src/AllocationPool.h @@ -0,0 +1,50 @@ + +#pragma once + +template +class AllocationPool { + public: + + ~AllocationPool() + { + while (!m_FreeList.empty()) + { + delete m_FreeList.front(); + m_FreeList.pop_front(); + } + } + + T* Allocate() + { + if (m_FreeList.Size() <= BufferSize) + { + try + { + return new T; + } + catch (std::bad_alloc& ex) + { + if (m_FreeList.size() == BufferSize) + { + StarvationCallbacks.OnStartingUsingBuffer(); + } + else if (m_FreeList.empty()) + { + StarvationCallbacks.OnBufferEmpty(); + // Try again until the memory is avalable + return Allocate(); + } + } + } + T* ret = m_FreeList.front(); + m_FreeList.pop_front(); + return ret; + } + void Free(T* ptr) + { + m_FreeList.push_front(ptr); + } + + private: + std::list m_FreeList; +} -- cgit v1.2.3 From 4124eac15d6b545b685e58f9f5f3a0266c1d8df0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 21:30:08 +0100 Subject: Added callback for stopping starvation mode --- src/AllocationPool.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index f03897f98..f1e324953 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -43,6 +43,10 @@ class AllocationPool { void Free(T* ptr) { m_FreeList.push_front(ptr); + if (m_FreeList.size() == BufferSize) + { + StarvationCallbacks.OnStopUsingBuffer(); + } } private: -- cgit v1.2.3 From 6991c2dd84060f8e7375966d4e488a359b42d43a Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 23 May 2014 15:48:09 +0100 Subject: Use placement new to initalise objects --- src/AllocationPool.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index f1e324953..d14d56f7a 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -36,12 +36,15 @@ class AllocationPool { } } } - T* ret = m_FreeList.front(); + // placement new, used to initalize the object + T* ret = new (m_FreeList.front()) T; m_FreeList.pop_front(); return ret; } void Free(T* ptr) { + // placement destruct. + ptr->~T(); m_FreeList.push_front(ptr); if (m_FreeList.size() == BufferSize) { @@ -50,5 +53,5 @@ class AllocationPool { } private: - std::list m_FreeList; + std::list m_FreeList; } -- cgit v1.2.3 From 8be3a8f7dc10dbc49dfcdeca572677ef1e00f714 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 23 May 2014 17:18:11 +0100 Subject: Implemented Allocation Pool use by cChunkData --- src/AllocationPool.h | 39 ++++++++++++++++++++++++++++----------- src/Chunk.cpp | 4 +++- src/Chunk.h | 3 ++- src/ChunkData.cpp | 6 +++--- src/ChunkData.h | 33 ++++++++++++++++++++++----------- src/ChunkMap.cpp | 11 +++++++---- src/ChunkMap.h | 15 ++++++++++++++- 7 files changed, 79 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index d14d56f7a..b3818e8b1 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -1,36 +1,52 @@ #pragma once -template -class AllocationPool { +#include + +template +class cAllocationPool { public: + + class cStarvationCallbacks + { + public: + virtual ~cStarvationCallbacks() {} + virtual void OnStartingUsingBuffer() = 0; + virtual void OnStopUsingBuffer() = 0; + virtual void OnBufferEmpty() = 0; + }; + + cAllocationPool(std::auto_ptr a_Callbacks) : + m_Callbacks(a_Callbacks) + { + } - ~AllocationPool() + ~cAllocationPool() { while (!m_FreeList.empty()) { - delete m_FreeList.front(); + free (m_FreeList.front()); m_FreeList.pop_front(); } } T* Allocate() { - if (m_FreeList.Size() <= BufferSize) + if (m_FreeList.size() <= BufferSize) { try { - return new T; + return new(malloc(sizeof(T))) T; } - catch (std::bad_alloc& ex) + catch (std::bad_alloc&) { if (m_FreeList.size() == BufferSize) { - StarvationCallbacks.OnStartingUsingBuffer(); + m_Callbacks->OnStartingUsingBuffer(); } else if (m_FreeList.empty()) { - StarvationCallbacks.OnBufferEmpty(); + m_Callbacks->OnBufferEmpty(); // Try again until the memory is avalable return Allocate(); } @@ -48,10 +64,11 @@ class AllocationPool { m_FreeList.push_front(ptr); if (m_FreeList.size() == BufferSize) { - StarvationCallbacks.OnStopUsingBuffer(); + m_Callbacks->OnStopUsingBuffer(); } } private: std::list m_FreeList; -} + std::auto_ptr m_Callbacks; +}; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index d85b44607..cdec0774f 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -64,7 +64,8 @@ sSetBlock::sSetBlock( int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_Bloc cChunk::cChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ, cChunkMap * a_ChunkMap, cWorld * a_World, - cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP + cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, + cAllocationPool& a_Pool ) : m_IsValid(false), m_IsLightValid(false), @@ -77,6 +78,7 @@ cChunk::cChunk( m_PosZ(a_ChunkZ), m_World(a_World), m_ChunkMap(a_ChunkMap), + m_ChunkData(a_Pool), m_BlockTickX(0), m_BlockTickY(0), m_BlockTickZ(0), diff --git a/src/Chunk.h b/src/Chunk.h index 2de45919e..e5b55ed2a 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -65,7 +65,8 @@ public: cChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ, // Chunk coords cChunkMap * a_ChunkMap, cWorld * a_World, // Parent objects - cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP // Neighbor chunks + cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, // Neighbor chunks + cAllocationPool& a_Pool ); cChunk(cChunk& other); ~cChunk(); diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index 86b0c431c..31de364b9 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -4,7 +4,7 @@ cChunkData cChunkData::Copy() const { - cChunkData copy; + cChunkData copy(m_Pool); for (int i = 0; i < CHUNK_SECTION_NUM; i++) { if (m_Sections[i] != NULL) @@ -360,14 +360,14 @@ void cChunkData::SetSkyLight (const NIBBLETYPE * a_src) cChunkData::sChunkSection * cChunkData::Allocate() const { // TODO: use a allocation pool - return new cChunkData::sChunkSection; + return m_Pool.Allocate(); } void cChunkData::Free(cChunkData::sChunkSection * ptr) const { - delete ptr; + m_Pool.Free(ptr); } diff --git a/src/ChunkData.h b/src/ChunkData.h index 9c852ee24..527c5b2ae 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -7,6 +7,8 @@ #include "ChunkDef.h" +#include "AllocationPool.h" + #define CHUNK_SECTION_HEIGHT 16 #define CHUNK_SECTION_NUM (256 / CHUNK_SECTION_HEIGHT) @@ -21,11 +23,14 @@ class cChunkData { public: - cChunkData() + struct sChunkSection; + + cChunkData(cAllocationPool& a_Pool) : #if __cplusplus < 201103L // auto_ptr style interface for memory management - : IsOwner(true) + IsOwner(true), #endif + m_Pool(a_Pool) { memset(m_Sections, 0, sizeof(m_Sections)); } @@ -44,7 +49,8 @@ public: #if __cplusplus < 201103L // auto_ptr style interface for memory management cChunkData(const cChunkData& other) : - IsOwner(true) + IsOwner(true), + m_Pool(other.m_Pool) { for (int i = 0; i < CHUNK_SECTION_NUM; i++) { @@ -70,13 +76,15 @@ public: m_Sections[i] = other.m_Sections[i]; } other.IsOwner = false; + ASSERT(&m_Pool == &other.m_Pool); } return *this; } #else // unique_ptr style interface for memory management - cChunkData(cChunkData&& other) + cChunkData(cChunkData&& other) : + m_Pool(other.m_Pool) { for (int i = 0; i < CHUNK_SECTION_NUM; i++) { @@ -95,6 +103,7 @@ public: m_Sections[i] = other.m_Sections[i]; other.m_Sections[i] = 0; } + ASSERT(&m_Pool == &other.m_Pool); } return *this; } @@ -252,13 +261,6 @@ public: void SetLight (const NIBBLETYPE * a_src); void SetSkyLight (const NIBBLETYPE * a_src); -private: - - #if __cplusplus < 201103L - // auto_ptr style interface for memory management - mutable bool IsOwner; - #endif - struct sChunkSection { BLOCKTYPE m_BlockTypes [CHUNK_SECTION_HEIGHT * 16 * 16] ; NIBBLETYPE m_BlockMeta [CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; @@ -266,12 +268,21 @@ private: NIBBLETYPE m_BlockSkyLight[CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; }; +private: + + #if __cplusplus < 201103L + // auto_ptr style interface for memory management + mutable bool IsOwner; + #endif + sChunkSection *m_Sections[CHUNK_SECTION_NUM]; sChunkSection * Allocate() const; void Free(sChunkSection * ptr) const; void ZeroSection(sChunkSection * ptr) const; + + cAllocationPool& m_Pool; }; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index d3f44bef8..bf2b09342 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -34,7 +34,8 @@ // cChunkMap: cChunkMap::cChunkMap(cWorld * a_World ) - : m_World( a_World ) + : m_World( a_World ), + m_Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())) { } @@ -78,7 +79,7 @@ cChunkMap::cChunkLayer * cChunkMap::GetLayer(int a_LayerX, int a_LayerZ) } // Not found, create new: - cChunkLayer * Layer = new cChunkLayer(a_LayerX, a_LayerZ, this); + cChunkLayer * Layer = new cChunkLayer(a_LayerX, a_LayerZ, this, m_Pool); if (Layer == NULL) { LOGERROR("cChunkMap: Cannot create new layer, server out of memory?"); @@ -2646,11 +2647,13 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) //////////////////////////////////////////////////////////////////////////////// // cChunkMap::cChunkLayer: -cChunkMap::cChunkLayer::cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent) +cChunkMap::cChunkLayer::cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, + cAllocationPool& a_Pool) : m_LayerX( a_LayerX ) , m_LayerZ( a_LayerZ ) , m_Parent( a_Parent ) , m_NumChunksLoaded( 0 ) + , m_Pool(a_Pool) { memset(m_Chunks, 0, sizeof(m_Chunks)); } @@ -2692,7 +2695,7 @@ cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkY, int a_Ch cChunk * neixp = (LocalX < LAYER_SIZE - 1) ? m_Chunks[Index + 1] : m_Parent->FindChunk(a_ChunkX + 1, a_ChunkZ); cChunk * neizm = (LocalZ > 0) ? m_Chunks[Index - LAYER_SIZE] : m_Parent->FindChunk(a_ChunkX , a_ChunkZ - 1); cChunk * neizp = (LocalZ < LAYER_SIZE - 1) ? m_Chunks[Index + LAYER_SIZE] : m_Parent->FindChunk(a_ChunkX , a_ChunkZ + 1); - m_Chunks[Index] = new cChunk(a_ChunkX, 0, a_ChunkZ, m_Parent, m_Parent->GetWorld(), neixm, neixp, neizm, neizp); + m_Chunks[Index] = new cChunk(a_ChunkX, 0, a_ChunkZ, m_Parent, m_Parent->GetWorld(), neixm, neixp, neizm, neizp, m_Pool); } return m_Chunks[Index]; } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index c3deda088..1744c09d0 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -347,7 +347,8 @@ private: class cChunkLayer { public: - cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent); + cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, + cAllocationPool& a_Pool); ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ @@ -391,6 +392,16 @@ private: int m_LayerZ; cChunkMap * m_Parent; int m_NumChunksLoaded; + + cAllocationPool & m_Pool; + }; + + class cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks + { + virtual void OnStartingUsingBuffer() {} + virtual void OnStopUsingBuffer() {} + virtual void OnBufferEmpty() {} }; typedef std::list cChunkLayerList; @@ -423,6 +434,8 @@ private: /** The cChunkStay descendants that are currently enabled in this chunkmap */ cChunkStays m_ChunkStays; + cAllocationPool m_Pool; + cChunkPtr GetChunk (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate cChunkPtr GetChunkNoLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Doesn't load, doesn't generate -- cgit v1.2.3 From 25910873852252fb388059e78d88a293ccd9d797 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 25 May 2014 17:48:40 +0100 Subject: Fixed bug in freeing NULL pointers --- src/AllocationPool.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index b3818e8b1..643b44a6d 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -34,22 +34,20 @@ class cAllocationPool { { if (m_FreeList.size() <= BufferSize) { - try + void * space = malloc(sizeof(T)); + if (space != NULL) { - return new(malloc(sizeof(T))) T; + return new(space) T; } - catch (std::bad_alloc&) + else if (m_FreeList.size() == BufferSize) { - if (m_FreeList.size() == BufferSize) - { - m_Callbacks->OnStartingUsingBuffer(); - } - else if (m_FreeList.empty()) - { - m_Callbacks->OnBufferEmpty(); - // Try again until the memory is avalable - return Allocate(); - } + m_Callbacks->OnStartingUsingBuffer(); + } + else if (m_FreeList.empty()) + { + m_Callbacks->OnBufferEmpty(); + // Try again until the memory is avalable + return Allocate(); } } // placement new, used to initalize the object @@ -59,6 +57,10 @@ class cAllocationPool { } void Free(T* ptr) { + if (ptr == NULL) + { + return; + } // placement destruct. ptr->~T(); m_FreeList.push_front(ptr); -- cgit v1.2.3 From 2a7d199df68d11f6fd1fa2b4186faa00d0e81676 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 25 May 2014 18:26:10 +0100 Subject: Fixed bad merge --- src/ChunkData.cpp | 10 +++++----- src/ChunkData.h | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index 1bc3072c2..99421bc33 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -242,7 +242,7 @@ NIBBLETYPE cChunkData::GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) const cChunkData cChunkData::Copy() const { cChunkData copy(m_Pool); - for (int i = 0; i < CHUNK_SECTION_NUM; i++) + for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++) { if (m_Sections[i] != NULL) { @@ -432,7 +432,7 @@ void cChunkData::SetBlocks(const BLOCKTYPE * a_src) void cChunkData::SetMeta(const NIBBLETYPE * a_src) { - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; if (m_Sections[i] != NULL) @@ -484,10 +484,10 @@ void cChunkData::SetMeta(const NIBBLETYPE * a_src) -void cChunkData::SetLight(const NIBBLETYPE * a_src) +void cChunkData::SetBlockLight(const NIBBLETYPE * a_src) { if (!a_src) return; - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; if (m_Sections[i] != NULL) @@ -542,7 +542,7 @@ void cChunkData::SetLight(const NIBBLETYPE * a_src) void cChunkData::SetSkyLight (const NIBBLETYPE * a_src) { if (!a_src) return; - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; if (m_Sections[i] != NULL) diff --git a/src/ChunkData.h b/src/ChunkData.h index 08f1603bb..637771741 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -19,6 +19,11 @@ class cChunkData { +private: + + static const size_t CHUNK_SECTION_HEIGHT = 16; + static const size_t CHUNK_SECTION_COUNT = (256 / CHUNK_SECTION_HEIGHT); + public: struct sChunkSection; @@ -65,10 +70,6 @@ public: }; private: - - static const size_t CHUNK_SECTION_HEIGHT = 16; - static const size_t CHUNK_SECTION_COUNT = (256 / CHUNK_SECTION_HEIGHT); - #if __cplusplus < 201103L // auto_ptr style interface for memory management mutable bool IsOwner; -- cgit v1.2.3 From 061102c77860e7a31b7504ca52bb99e419393fb2 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 17:23:57 +0100 Subject: Added logging --- src/ChunkMap.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 1a3258f15..efe489854 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -403,9 +403,18 @@ private: class cStarvationCallbacks : public cAllocationPool::cStarvationCallbacks { - virtual void OnStartingUsingBuffer() {} - virtual void OnStopUsingBuffer() {} - virtual void OnBufferEmpty() {} + virtual void OnStartingUsingBuffer() + { + LOG("Using backup memory buffer"); + } + virtual void OnStopUsingBuffer() + { + LOG("Stoped using backup memory buffer"); + } + virtual void OnBufferEmpty() + { + LOG("Out of Memory"); + } }; typedef std::list cChunkLayerList; -- cgit v1.2.3 From 8bf37f3dd7ff017eedaac427b9291a9335d61efc Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 17:57:21 +0100 Subject: Fixed comments --- src/AllocationPool.h | 8 ++++---- src/ChunkData.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 643b44a6d..b8862e7df 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -3,7 +3,7 @@ #include -template +template class cAllocationPool { public: @@ -32,14 +32,14 @@ class cAllocationPool { T* Allocate() { - if (m_FreeList.size() <= BufferSize) + if (m_FreeList.size() <= NumElementsInReserve) { void * space = malloc(sizeof(T)); if (space != NULL) { return new(space) T; } - else if (m_FreeList.size() == BufferSize) + else if (m_FreeList.size() == NumElementsInReserve) { m_Callbacks->OnStartingUsingBuffer(); } @@ -64,7 +64,7 @@ class cAllocationPool { // placement destruct. ptr->~T(); m_FreeList.push_front(ptr); - if (m_FreeList.size() == BufferSize) + if (m_FreeList.size() == NumElementsInReserve) { m_Callbacks->OnStopUsingBuffer(); } diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index 24a2c3e14..a80b1de0f 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -30,9 +30,9 @@ template inline bool IsAllValue(const T * a_Array, size_t a_NumElem cChunkData::cChunkData(cAllocationPool& a_Pool) : #if __cplusplus < 201103L // auto_ptr style interface for memory management - m_IsOwner(true) + m_IsOwner(true), #endif -m_Pool(a_Pool) + m_Pool(a_Pool) { for (size_t i = 0; i < NumSections; i++) { -- cgit v1.2.3 From bff76f201ffec0cc4c4df2be6ac125efa985dce7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 17:59:47 +0100 Subject: Fill with buffer on startup --- src/AllocationPool.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index b8862e7df..e4f1427f6 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -19,6 +19,16 @@ class cAllocationPool { cAllocationPool(std::auto_ptr a_Callbacks) : m_Callbacks(a_Callbacks) { + for(int i = 0; i < NumElementsInReserve; i++) + { + void * space = malloc(sizeof(T)); + if (space == NULL) + { + m_Callbacks->OnStartingUsingBuffer(); + break; + } + m_FreeList.push_front(space); + } } ~cAllocationPool() -- cgit v1.2.3 From f6af584efa60d23c06abdc86dbfdfc85da23a3dc Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 18:11:43 +0100 Subject: fixed const issue --- src/ChunkData.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index a80b1de0f..d2903cff1 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -68,7 +68,7 @@ cChunkData::~cChunkData() // auto_ptr style interface for memory management cChunkData::cChunkData(const cChunkData & a_Other) : m_IsOwner(true), - m_Pool(other.m_Pool) + m_Pool(a_Other.m_Pool) { // Move contents and ownership from a_Other to this, pointer-wise: for (size_t i = 0; i < NumSections; i++) @@ -107,7 +107,7 @@ cChunkData::~cChunkData() m_Sections[i] = a_Other.m_Sections[i]; } a_Other.m_IsOwner = false; - ASSERT(&m_Pool == &other.m_Pool); + ASSERT(&m_Pool == &a_Other.m_Pool); return *this; } @@ -327,7 +327,7 @@ cChunkData cChunkData::Copy(void) const { if (m_Sections[i] != NULL) { - copy.m_Sections[i] = Allocate(); + copy.m_Sections[i] = copy.Allocate(); *copy.m_Sections[i] = *m_Sections[i]; } } -- cgit v1.2.3 From a2df68b80b3ccb4395922c4351d4bd2f366003db Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 18:19:34 +0100 Subject: fixed compile --- src/AllocationPool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index e4f1427f6..f73b32601 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -19,7 +19,7 @@ class cAllocationPool { cAllocationPool(std::auto_ptr a_Callbacks) : m_Callbacks(a_Callbacks) { - for(int i = 0; i < NumElementsInReserve; i++) + for(size_t i = 0; i < NumElementsInReserve; i++) { void * space = malloc(sizeof(T)); if (space == NULL) -- cgit v1.2.3 From 0310a50192fcbd4a9e5ec03c98a0d7f33457df54 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 18:43:36 +0100 Subject: fixed spaces --- src/AllocationPool.h | 2 +- src/ChunkMap.cpp | 2 +- src/ChunkMap.h | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index f73b32601..9144c2eac 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -19,7 +19,7 @@ class cAllocationPool { cAllocationPool(std::auto_ptr a_Callbacks) : m_Callbacks(a_Callbacks) { - for(size_t i = 0; i < NumElementsInReserve; i++) + for (size_t i = 0; i < NumElementsInReserve; i++) { void * space = malloc(sizeof(T)); if (space == NULL) diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 586d7a65e..862d0b7ec 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -35,7 +35,7 @@ cChunkMap::cChunkMap(cWorld * a_World ) : m_World( a_World ), - m_Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())) + m_Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())) { } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index efe489854..071921f92 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -352,7 +352,7 @@ private: { public: cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool& a_Pool); + cAllocationPool& a_Pool); ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ @@ -397,11 +397,11 @@ private: cChunkMap * m_Parent; int m_NumChunksLoaded; - cAllocationPool & m_Pool; + cAllocationPool & m_Pool; }; class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { virtual void OnStartingUsingBuffer() { @@ -447,7 +447,7 @@ private: /** The cChunkStay descendants that are currently enabled in this chunkmap */ cChunkStays m_ChunkStays; - cAllocationPool m_Pool; + cAllocationPool m_Pool; cChunkPtr GetChunk (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate -- cgit v1.2.3 From 6b99e556462fdbdf6a265c014fb03f070b0f1b25 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:05:02 +0100 Subject: fixed spaces --- src/AllocationPool.h | 11 ++++++----- src/Chunk.cpp | 2 +- src/Chunk.h | 2 +- src/ChunkData.cpp | 2 +- src/ChunkData.h | 7 ++++--- src/ChunkMap.cpp | 2 +- src/ChunkMap.h | 2 +- 7 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 9144c2eac..9bb44ff1f 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -4,7 +4,8 @@ #include template -class cAllocationPool { +class cAllocationPool +{ public: class cStarvationCallbacks @@ -17,7 +18,7 @@ class cAllocationPool { }; cAllocationPool(std::auto_ptr a_Callbacks) : - m_Callbacks(a_Callbacks) + m_Callbacks(a_Callbacks) { for (size_t i = 0; i < NumElementsInReserve; i++) { @@ -40,7 +41,7 @@ class cAllocationPool { } } - T* Allocate() + T * Allocate() { if (m_FreeList.size() <= NumElementsInReserve) { @@ -61,11 +62,11 @@ class cAllocationPool { } } // placement new, used to initalize the object - T* ret = new (m_FreeList.front()) T; + T * ret = new (m_FreeList.front()) T; m_FreeList.pop_front(); return ret; } - void Free(T* ptr) + void Free(T * ptr) { if (ptr == NULL) { diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 64a5660d8..a0a397a08 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -65,7 +65,7 @@ cChunk::cChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ, cChunkMap * a_ChunkMap, cWorld * a_World, cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, - cAllocationPool& a_Pool + cAllocationPool & a_Pool ) : m_IsValid(false), m_IsLightValid(false), diff --git a/src/Chunk.h b/src/Chunk.h index 7309fd022..07f597d59 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -66,7 +66,7 @@ public: int a_ChunkX, int a_ChunkY, int a_ChunkZ, // Chunk coords cChunkMap * a_ChunkMap, cWorld * a_World, // Parent objects cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, // Neighbor chunks - cAllocationPool& a_Pool + cAllocationPool & a_Pool ); cChunk(cChunk & other); ~cChunk(); diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index d2903cff1..f9c263d88 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -27,7 +27,7 @@ template inline bool IsAllValue(const T * a_Array, size_t a_NumElem -cChunkData::cChunkData(cAllocationPool& a_Pool) : +cChunkData::cChunkData(cAllocationPool & a_Pool) : #if __cplusplus < 201103L // auto_ptr style interface for memory management m_IsOwner(true), diff --git a/src/ChunkData.h b/src/ChunkData.h index aaefc4575..9dee78ad0 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -37,7 +37,7 @@ public: struct sChunkSection; - cChunkData(cAllocationPool& a_Pool); + cChunkData(cAllocationPool & a_Pool); ~cChunkData(); #if __cplusplus < 201103L @@ -96,7 +96,8 @@ public: Allows a_Src to be NULL, in which case it doesn't do anything. */ void SetSkyLight(const NIBBLETYPE * a_Src); - struct sChunkSection { + struct sChunkSection + { BLOCKTYPE m_BlockTypes [SectionHeight * 16 * 16] ; NIBBLETYPE m_BlockMetas [SectionHeight * 16 * 16 / 2]; NIBBLETYPE m_BlockLight [SectionHeight * 16 * 16 / 2]; @@ -121,7 +122,7 @@ private: /** Sets the data in the specified section to their default values. */ void ZeroSection(sChunkSection * a_Section) const; - cAllocationPool& m_Pool; + cAllocationPool & m_Pool; }; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 862d0b7ec..704c4f823 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2672,7 +2672,7 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) // cChunkMap::cChunkLayer: cChunkMap::cChunkLayer::cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool& a_Pool) + cAllocationPool & a_Pool) : m_LayerX( a_LayerX ) , m_LayerZ( a_LayerZ ) , m_Parent( a_Parent ) diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 071921f92..08156e7e6 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -352,7 +352,7 @@ private: { public: cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool& a_Pool); + cAllocationPool & a_Pool); ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ -- cgit v1.2.3 From 94c48febd2f596648fc2616a8a577316a219b581 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:46:34 +0100 Subject: Added generic Allocation Pool Interface --- src/AllocationPool.h | 46 ++++++++++++++++++++++++++++------------------ src/Chunk.cpp | 2 +- src/Chunk.h | 2 +- src/ChunkData.cpp | 2 +- src/ChunkData.h | 4 ++-- src/ChunkMap.cpp | 12 +++++++++--- src/ChunkMap.h | 8 ++++---- 7 files changed, 46 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 9bb44ff1f..88bc132e9 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -3,21 +3,31 @@ #include +template +class cAllocationPool +{ +public: + class cStarvationCallbacks + { + public: + virtual ~cStarvationCallbacks() {} + virtual void OnStartingUsingBuffer() = 0; + virtual void OnStopUsingBuffer() = 0; + virtual void OnBufferEmpty() = 0; + }; + + virtual ~cAllocationPool() {} + + virtual T * Allocate() = 0; + virtual void Free(T * a_ptr) = 0; +}; + template -class cAllocationPool +class cListAllocationPool : public cAllocationPool { public: - - class cStarvationCallbacks - { - public: - virtual ~cStarvationCallbacks() {} - virtual void OnStartingUsingBuffer() = 0; - virtual void OnStopUsingBuffer() = 0; - virtual void OnBufferEmpty() = 0; - }; - cAllocationPool(std::auto_ptr a_Callbacks) : + cListAllocationPool(std::auto_ptr::cStarvationCallbacks> a_Callbacks) : m_Callbacks(a_Callbacks) { for (size_t i = 0; i < NumElementsInReserve; i++) @@ -32,7 +42,7 @@ class cAllocationPool } } - ~cAllocationPool() + virtual ~cListAllocationPool() { while (!m_FreeList.empty()) { @@ -41,7 +51,7 @@ class cAllocationPool } } - T * Allocate() + virtual T * Allocate() override { if (m_FreeList.size() <= NumElementsInReserve) { @@ -66,15 +76,15 @@ class cAllocationPool m_FreeList.pop_front(); return ret; } - void Free(T * ptr) + virtual void Free(T * a_ptr) override { - if (ptr == NULL) + if (a_ptr == NULL) { return; } // placement destruct. - ptr->~T(); - m_FreeList.push_front(ptr); + a_ptr->~T(); + m_FreeList.push_front(a_ptr); if (m_FreeList.size() == NumElementsInReserve) { m_Callbacks->OnStopUsingBuffer(); @@ -83,5 +93,5 @@ class cAllocationPool private: std::list m_FreeList; - std::auto_ptr m_Callbacks; + std::auto_ptr::cStarvationCallbacks> m_Callbacks; }; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a0a397a08..4703e4536 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -65,7 +65,7 @@ cChunk::cChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ, cChunkMap * a_ChunkMap, cWorld * a_World, cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, - cAllocationPool & a_Pool + cAllocationPool & a_Pool ) : m_IsValid(false), m_IsLightValid(false), diff --git a/src/Chunk.h b/src/Chunk.h index 07f597d59..7664a7afd 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -66,7 +66,7 @@ public: int a_ChunkX, int a_ChunkY, int a_ChunkZ, // Chunk coords cChunkMap * a_ChunkMap, cWorld * a_World, // Parent objects cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, // Neighbor chunks - cAllocationPool & a_Pool + cAllocationPool & a_Pool ); cChunk(cChunk & other); ~cChunk(); diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index f9c263d88..03b0224a6 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -27,7 +27,7 @@ template inline bool IsAllValue(const T * a_Array, size_t a_NumElem -cChunkData::cChunkData(cAllocationPool & a_Pool) : +cChunkData::cChunkData(cAllocationPool & a_Pool) : #if __cplusplus < 201103L // auto_ptr style interface for memory management m_IsOwner(true), diff --git a/src/ChunkData.h b/src/ChunkData.h index 9dee78ad0..e3b36c581 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -37,7 +37,7 @@ public: struct sChunkSection; - cChunkData(cAllocationPool & a_Pool); + cChunkData(cAllocationPool & a_Pool); ~cChunkData(); #if __cplusplus < 201103L @@ -122,7 +122,7 @@ private: /** Sets the data in the specified section to their default values. */ void ZeroSection(sChunkSection * a_Section) const; - cAllocationPool & m_Pool; + cAllocationPool & m_Pool; }; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 704c4f823..3b946f9ec 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -35,8 +35,14 @@ cChunkMap::cChunkMap(cWorld * a_World ) : m_World( a_World ), - m_Pool(std::auto_ptr::cStarvationCallbacks>(new cStarvationCallbacks())) + m_Pool( + new cListAllocationPool( + std::auto_ptr::cStarvationCallbacks>( + new cStarvationCallbacks()) + ) + ) { + } @@ -79,7 +85,7 @@ cChunkMap::cChunkLayer * cChunkMap::GetLayer(int a_LayerX, int a_LayerZ) } // Not found, create new: - cChunkLayer * Layer = new cChunkLayer(a_LayerX, a_LayerZ, this, m_Pool); + cChunkLayer * Layer = new cChunkLayer(a_LayerX, a_LayerZ, this, *m_Pool); if (Layer == NULL) { LOGERROR("cChunkMap: Cannot create new layer, server out of memory?"); @@ -2672,7 +2678,7 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) // cChunkMap::cChunkLayer: cChunkMap::cChunkLayer::cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool & a_Pool) + cAllocationPool & a_Pool) : m_LayerX( a_LayerX ) , m_LayerZ( a_LayerZ ) , m_Parent( a_Parent ) diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 08156e7e6..c1dc743e5 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -352,7 +352,7 @@ private: { public: cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool & a_Pool); + cAllocationPool & a_Pool); ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ @@ -397,11 +397,11 @@ private: cChunkMap * m_Parent; int m_NumChunksLoaded; - cAllocationPool & m_Pool; + cAllocationPool & m_Pool; }; class cStarvationCallbacks - : public cAllocationPool::cStarvationCallbacks + : public cAllocationPool::cStarvationCallbacks { virtual void OnStartingUsingBuffer() { @@ -447,7 +447,7 @@ private: /** The cChunkStay descendants that are currently enabled in this chunkmap */ cChunkStays m_ChunkStays; - cAllocationPool m_Pool; + std::auto_ptr> m_Pool; cChunkPtr GetChunk (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate -- cgit v1.2.3 From 3efbdb1c9b8f83ecb28992282c08aa065e21e1f8 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:54:09 +0100 Subject: Moved m_Sections --- src/ChunkData.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChunkData.h b/src/ChunkData.h index e3b36c581..fe8b068a2 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -111,6 +111,8 @@ private: #endif sChunkSection * m_Sections[NumSections]; + + cAllocationPool & m_Pool; /** Allocates a new section. Entry-point to custom allocators. */ sChunkSection * Allocate(void); @@ -122,7 +124,6 @@ private: /** Sets the data in the specified section to their default values. */ void ZeroSection(sChunkSection * a_Section) const; - cAllocationPool & m_Pool; }; -- cgit v1.2.3 From f97116141f464d4e27515197eec7d42f9d2ba772 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:56:01 +0100 Subject: Reformated ChunkMap.h --- src/ChunkMap.cpp | 7 +++++-- src/ChunkMap.h | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 3b946f9ec..d2ccca94e 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2677,8 +2677,11 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ) //////////////////////////////////////////////////////////////////////////////// // cChunkMap::cChunkLayer: -cChunkMap::cChunkLayer::cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool & a_Pool) +cChunkMap::cChunkLayer::cChunkLayer( + int a_LayerX, int a_LayerZ, + cChunkMap * a_Parent, + cAllocationPool & a_Pool +) : m_LayerX( a_LayerX ) , m_LayerZ( a_LayerZ ) , m_Parent( a_Parent ) diff --git a/src/ChunkMap.h b/src/ChunkMap.h index c1dc743e5..0d6f1f80a 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -351,8 +351,11 @@ private: class cChunkLayer { public: - cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent, - cAllocationPool & a_Pool); + cChunkLayer( + int a_LayerX, int a_LayerZ, + cChunkMap * a_Parent, + cAllocationPool & a_Pool + ); ~cChunkLayer(); /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ -- cgit v1.2.3 From 2643a46c69d7d1354ec324a274dba4ccca315f3c Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 20:04:35 +0100 Subject: Documented cAllocationPool --- src/AllocationPool.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 88bc132e9..cac5689b9 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -18,10 +18,15 @@ public: virtual ~cAllocationPool() {} + /** Allocates a pointer to T **/ virtual T * Allocate() = 0; + + /** Frees the pointer passed in a_ptr, invalidating it **/ virtual void Free(T * a_ptr) = 0; }; +/** Allocates memory storing unused elements in a linked list. Keeps at least NumElementsInReserve + elements in the list unless malloc fails so that the program has a reserve to handle OOM.**/ template class cListAllocationPool : public cAllocationPool { -- cgit v1.2.3 From 41e5a64ff8f268f2cb0278e691f300e3a1790388 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 20:07:17 +0100 Subject: Documented starvation callbacks --- src/AllocationPool.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index cac5689b9..b7d0bb506 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -11,8 +11,15 @@ public: { public: virtual ~cStarvationCallbacks() {} + + /** Is called when the reserve buffer starts to be used **/ virtual void OnStartingUsingBuffer() = 0; + + /** Is called once the reserve buffer has returned to normal size **/ virtual void OnStopUsingBuffer() = 0; + + /** Is called when the allocation pool is unable to allocate memory. Will be repeatedly + called if it does not free sufficient memory **/ virtual void OnBufferEmpty() = 0; }; -- cgit v1.2.3 From 6ddcf42409b0460091abf0bb94b01043dd1b112b Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 20:10:49 +0100 Subject: Removed spaces --- src/AllocationPool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index b7d0bb506..9c833302f 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -19,7 +19,7 @@ public: virtual void OnStopUsingBuffer() = 0; /** Is called when the allocation pool is unable to allocate memory. Will be repeatedly - called if it does not free sufficient memory **/ + called if it does not free sufficient memory **/ virtual void OnBufferEmpty() = 0; }; @@ -33,7 +33,7 @@ public: }; /** Allocates memory storing unused elements in a linked list. Keeps at least NumElementsInReserve - elements in the list unless malloc fails so that the program has a reserve to handle OOM.**/ +elements in the list unless malloc fails so that the program has a reserve to handle OOM.**/ template class cListAllocationPool : public cAllocationPool { -- cgit v1.2.3 From 8a2aa6cb169563c7df752821e032b1cab1bac5d1 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 20:24:52 +0100 Subject: Changed names of callbacks --- src/AllocationPool.h | 14 +++++++------- src/ChunkMap.h | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 9c833302f..5d749a79e 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -13,14 +13,14 @@ public: virtual ~cStarvationCallbacks() {} /** Is called when the reserve buffer starts to be used **/ - virtual void OnStartingUsingBuffer() = 0; + virtual void OnStartUsingReserve() = 0; /** Is called once the reserve buffer has returned to normal size **/ - virtual void OnStopUsingBuffer() = 0; + virtual void OnEndUsingReserve() = 0; /** Is called when the allocation pool is unable to allocate memory. Will be repeatedly called if it does not free sufficient memory **/ - virtual void OnBufferEmpty() = 0; + virtual void OnOutOfReserve() = 0; }; virtual ~cAllocationPool() {} @@ -47,7 +47,7 @@ class cListAllocationPool : public cAllocationPool void * space = malloc(sizeof(T)); if (space == NULL) { - m_Callbacks->OnStartingUsingBuffer(); + m_Callbacks->OnStartUsingReserve(); break; } m_FreeList.push_front(space); @@ -74,11 +74,11 @@ class cListAllocationPool : public cAllocationPool } else if (m_FreeList.size() == NumElementsInReserve) { - m_Callbacks->OnStartingUsingBuffer(); + m_Callbacks->OnStartUsingReserve(); } else if (m_FreeList.empty()) { - m_Callbacks->OnBufferEmpty(); + m_Callbacks->OnOutOfReserve(); // Try again until the memory is avalable return Allocate(); } @@ -99,7 +99,7 @@ class cListAllocationPool : public cAllocationPool m_FreeList.push_front(a_ptr); if (m_FreeList.size() == NumElementsInReserve) { - m_Callbacks->OnStopUsingBuffer(); + m_Callbacks->OnEndUsingReserve(); } } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 0d6f1f80a..fd319fbc9 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -406,15 +406,15 @@ private: class cStarvationCallbacks : public cAllocationPool::cStarvationCallbacks { - virtual void OnStartingUsingBuffer() + virtual void OnStartUsingReserve() { LOG("Using backup memory buffer"); } - virtual void OnStopUsingBuffer() + virtual void OnEndUsingReserve() { LOG("Stoped using backup memory buffer"); } - virtual void OnBufferEmpty() + virtual void OnOutOfReserve() { LOG("Out of Memory"); } -- cgit v1.2.3 From 1e57161ecc09ca9aa009b5c4795113aae95d89ea Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 16 Jun 2014 14:12:10 +0100 Subject: Added override --- src/ChunkMap.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ChunkMap.h b/src/ChunkMap.h index fd319fbc9..5aad0dd2a 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -406,15 +406,15 @@ private: class cStarvationCallbacks : public cAllocationPool::cStarvationCallbacks { - virtual void OnStartUsingReserve() + virtual void OnStartUsingReserve() override { LOG("Using backup memory buffer"); } - virtual void OnEndUsingReserve() + virtual void OnEndUsingReserve() override { LOG("Stoped using backup memory buffer"); } - virtual void OnOutOfReserve() + virtual void OnOutOfReserve() override { LOG("Out of Memory"); } -- cgit v1.2.3