A 3D game engine from scratch.
at main 38 lines 905 B view raw
1// (c) 2020 Vlad-Stefan Harbuz <vlad@vladh.net> 2 3#pragma once 4 5#include "types.hpp" 6 7#define MEMORY_PUSH(pool, type, debug_name) \ 8 (type*)memory::push(pool, sizeof(type), debug_name) 9 10class memory { 11public: 12#if USE_MEMORYPOOL_ITEM_DEBUG 13 constexpr u32 MAX_N_MEMORYPOOL_ITEMS = 1024; 14#endif 15 16 struct Pool { 17 u8 *memory; 18 size_t size; 19 size_t used; 20 u32 n_items; 21 #if USE_MEMORYPOOL_ITEM_DEBUG 22 const char *item_debug_names[MAX_N_MEMORYPOOL_ITEMS]; 23 size_t item_debug_sizes[MAX_N_MEMORYPOOL_ITEMS]; 24 #endif 25 }; 26 27 static void * push( 28 Pool *pool, 29 size_t item_size, 30 const char *item_debug_name 31 ); 32 static void print_memory_pool(Pool *pool); 33 static void destroy_memory_pool(Pool *memory_pool); 34 35private: 36 static void reset_memory_pool(Pool *pool); 37 static void zero_out_memory_pool(Pool *pool); 38};