#pragma once #include #include // Memory needed for the duration of a frame rendering class RenderMemory { public: void Clear(); template T *AllocMemory(int size = 1) { return (T*)AllocBytes(sizeof(T) * size); } template T *NewObject(Types &&... args) { void *ptr = AllocBytes(sizeof(T)); return new (ptr)T(std::forward(args)...); } private: void *AllocBytes(int size); enum { BlockSize = 1024 * 1024 }; struct MemoryBlock { MemoryBlock() : Data(new uint8_t[BlockSize]), Position(0) { } ~MemoryBlock() { delete[] Data; } MemoryBlock(const MemoryBlock &) = delete; MemoryBlock &operator=(const MemoryBlock &) = delete; uint8_t *Data; uint32_t Position; }; std::vector> UsedBlocks; std::vector> FreeBlocks; };