Memory pool interface.
More...
#include <TMemoryPool.hpp>
Memory pool interface.
Definition at line 22 of file TMemoryPool.hpp.
◆ Byte
◆ Lock
◆ Mutex
◆ Size
◆ MemoryPool()
tklb::memory::MemoryPool::MemoryPool |
( |
void * |
pool, |
|
|
Size |
size |
|
) |
| |
|
inline |
Construct a pool from memory provided.
The first few bytes need to be zero to indicate when the pool needs to be initialized.
Definition at line 76 of file TMemoryPool.hpp.
76 :
mPool(*
static_cast<SharedPool*
>(pool)) {
80 SharedPool* p =
new (pool) SharedPool();
#define TKLB_ASSERT(condition)
Wrap assertions.
Byte * memory
Start of the usable pool space this does not store the pointer, but the location location itself is u...
◆ ~MemoryPool()
tklb::memory::MemoryPool::~MemoryPool |
( |
| ) |
|
|
inline |
◆ allocate()
virtual void * tklb::memory::MemoryPool::allocate |
( |
Size |
size | ) |
|
|
pure virtual |
◆ allocateAligned()
Allocate aligned if simd is enabled.
Does a normal allocation otherwise.
Definition at line 173 of file TMemoryPool.hpp.
175 void* result =
allocate(size + align);
176 if (result !=
nullptr && align != 0) {
178 const Size mask = ~(
Size(align - 1));
179 const Size pointer =
reinterpret_cast<Size>(result);
180 const Size floored = pointer & mask;
181 const Size aligned = floored + align;
187 result =
reinterpret_cast<void*
>(aligned);
188 Size* original =
reinterpret_cast<Size*
>(result) - 1;
189 *(original) = pointer;
virtual void * allocate(Size size)=0
◆ clearallocate()
void * tklb::memory::MemoryPool::clearallocate |
( |
size_t |
num, |
|
|
size_t |
size |
|
) |
| |
|
inline |
Allocates space for num of structs with size size and clears the memory.
- Parameters
-
num | Number of structs |
size | Size of a single struct |
Definition at line 111 of file TMemoryPool.hpp.
112 const size_t total = size * num;
114 if (ptr ==
nullptr) {
return nullptr; }
static void set(void *dst, const unsigned char val, size_t size)
memset wrapper
◆ create()
template<class T , typename ... Args>
T * tklb::memory::MemoryPool::create |
( |
Args &&... |
args | ) |
|
|
inline |
Acts like new.
Allocate and construct object.
- Parameters
-
args | Arguments passed to class contructor |
Definition at line 124 of file TMemoryPool.hpp.
126 if (ptr ==
nullptr) {
return nullptr; }
127 new (ptr) T(std::forward<Args>(args)...);
128 return reinterpret_cast<T*
>(ptr);
◆ createArray()
template<class T , typename ... Args>
T * tklb::memory::MemoryPool::createArray |
( |
size_t |
count, |
|
|
Args &&... |
args |
|
) |
| |
|
inline |
Definition at line 132 of file TMemoryPool.hpp.
133 unsigned char* ptr =
reinterpret_cast<unsigned char*
>(
allocate(
sizeof(T) * count));
134 if (ptr ==
nullptr) {
return nullptr; }
135 for (
size_t i = 0; i < count; i++) {
136 new (ptr + i *
sizeof(T)) T(std::forward<Args>(args)...);
138 return reinterpret_cast<T*
>(ptr);
◆ deallocate()
virtual void tklb::memory::MemoryPool::deallocate |
( |
void * |
ptr | ) |
|
|
pure virtual |
◆ deallocateAligned()
void tklb::memory::MemoryPool::deallocateAligned |
( |
void * |
ptr | ) |
|
|
inline |
Definition at line 163 of file TMemoryPool.hpp.
164 if (ptr ==
nullptr) {
return; }
166 deallocate(*(
reinterpret_cast<void**
>(ptr) - 1));
virtual void deallocate(void *ptr)=0
◆ dispose()
template<class T >
void tklb::memory::MemoryPool::dispose |
( |
T * |
ptr | ) |
|
|
inline |
Acts like delete.
Destroy the object and dispose the memory.
Definition at line 145 of file TMemoryPool.hpp.
146 if (ptr ==
nullptr) {
return; }
◆ disposeArray()
template<class T >
void tklb::memory::MemoryPool::disposeArray |
( |
size_t |
count, |
|
|
T * |
ptr |
|
) |
| |
|
inline |
Acts like delete.
Destroy the object and dispose the memory.
Definition at line 155 of file TMemoryPool.hpp.
156 if (ptr ==
nullptr) {
return; }
157 for (
size_t i = 0; i < count; i++) {
158 (ptr + i *
sizeof(T))->~T();
◆ getAllocated()
Size tklb::memory::MemoryPool::getAllocated |
( |
| ) |
const |
|
inline |
◆ getTotalSize()
Size tklb::memory::MemoryPool::getTotalSize |
( |
| ) |
const |
|
inline |
◆ reallocate()
virtual void * tklb::memory::MemoryPool::reallocate |
( |
void * |
ptr, |
|
|
size_t |
size |
|
) |
| |
|
pure virtual |
◆ DEFAULT_ALIGN
constexpr Size tklb::memory::MemoryPool::DEFAULT_ALIGN = xsimd::default_arch::alignment() |
|
staticconstexprprotected |
◆ mPool
The documentation for this class was generated from the following file: