5 #ifndef _SPICA_MEMORY_H_
6 #define _SPICA_MEMORY_H_
10 #include "../core/common.h"
11 #include "../core/uncopyable.h"
24 class SPICA_EXPORTS MEM_ALIGN(64) MemoryArena :
private Uncopyable {
26 MemoryArena(
size_t blockSize = 262144);
27 MemoryArena(MemoryArena&& arena) noexcept;
28 virtual ~MemoryArena();
30 MemoryArena& operator=(MemoryArena&& arena) = delete;
32 void* allocate(
size_t nBytes);
34 template <class T, class... Args>
35 T* allocate(const Args&... args) {
36 T* ret = (T*)allocate(
sizeof(T));
43 size_t totalAllocated()
const;
47 const size_t blockSize_;
48 size_t currentBlockPos_ = 0;
49 size_t currentAllocSize_ = 0;
50 unsigned char* currentBlock_ =
nullptr;
51 std::list<std::pair<size_t, unsigned char*>> usedBlocks_, availableBlocks_;
56 #endif // _SPICA_MEMORY_H_