1 #ifndef GRAIL_POOL_ALLOCATOR_H
2 #define GRAIL_POOL_ALLOCATOR_H
4 #include "../GrailSystem/consts.h"
17 Emplacer(
typename std::enable_if<std::is_trivially_destructible<T>::value>::type* = 0)
21 template <
typename... Arguments>
22 T& operator()(
void* memoryCell, Arguments&&... arguments)
24 return *(
new(memoryCell) T{std::forward<Arguments>(arguments)...});
32 template <
typename... Arguments>
33 std::string& operator()(
void* memoryCell, Arguments&&... arguments)
35 if(StringLength(std::forward<Arguments>(arguments)...) > consts::MAX_STRING_SIZE)
37 throw std::bad_alloc{};
39 return *(
new(memoryCell) std::string{std::forward<Arguments>(arguments)...});
43 std::size_t StringLength(
const std::string&
string)
const
53 template <
typename... Arguments>
54 const std::string& operator()(
void* memoryCell, Arguments&&... arguments)
56 if(StringLength(std::forward<Arguments>(arguments)...) > consts::MAX_STRING_SIZE)
58 throw std::bad_alloc{};
60 return *(
new(memoryCell)
const std::string{std::forward<Arguments>(arguments)...});
64 std::size_t StringLength(
const std::string&
string)
const
82 : blocks{new char[BYTES]}, currentMemoryCell{&blocks[0]}, _size{0},
92 template<
typename T,
typename... ConstructorArguments>
93 T& Emplace(ConstructorArguments&&... arguments)
95 std::size_t memoryRequired =
sizeof(T);
96 _size += memoryRequired;
100 throw std::bad_alloc{};
103 Emplacer<T> emplacer;
104 T& result = emplacer(currentMemoryCell, std::forward<ConstructorArguments>(arguments)...);
105 currentMemoryCell =
static_cast<char*
>(currentMemoryCell) + memoryRequired;
109 std::size_t Size()
const
116 currentMemoryCell = &blocks[0];
122 void* currentMemoryCell;
124 const std::size_t BYTES;
Definition: MemoryPool.hh:15
The MemoryPool class - preallocated memory container for optimization issues.
Definition: MemoryPool.hh:74
MemoryPool(const std::size_t BYTES=5242880u)
MemoryPool.
Definition: MemoryPool.hh:81