summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-05-25 18:48:40 +0200
committerTycho <work.tycho+git@gmail.com>2014-05-25 18:48:40 +0200
commit25910873852252fb388059e78d88a293ccd9d797 (patch)
tree426308e2aa56f1f60e4ee2570f5bdbbec81ea906
parentImplemented Allocation Pool use by cChunkData (diff)
downloadcuberite-25910873852252fb388059e78d88a293ccd9d797.tar
cuberite-25910873852252fb388059e78d88a293ccd9d797.tar.gz
cuberite-25910873852252fb388059e78d88a293ccd9d797.tar.bz2
cuberite-25910873852252fb388059e78d88a293ccd9d797.tar.lz
cuberite-25910873852252fb388059e78d88a293ccd9d797.tar.xz
cuberite-25910873852252fb388059e78d88a293ccd9d797.tar.zst
cuberite-25910873852252fb388059e78d88a293ccd9d797.zip
Diffstat (limited to '')
-rw-r--r--src/AllocationPool.h28
1 files changed, 15 insertions, 13 deletions
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);