#pragma once #include "shm.h" #include "page_heap.h" #include "size_map.h" namespace bg { namespace detail { struct ChunkCache { struct ClassCache { Span free_list; size_t span_count{}; }; ClassCache m_caches[87]{}; }; class ShmManager { public: struct ShmBlock { void* addr{}; size_t used_size{}; size_t real_size{}; size_t mmap_size{}; }; ShmManager(const bg::ShmOptions&); ~ShmManager(); void* AllocateRawMemory(size_t* bytes, size_t alignment); bool HasSingleton(const bg::detail::TypeName& type); void* GetSingleton(const bg::detail::TypeName& type, size_t bytes, bool* first_call); void FreeSingleton(const bg::detail::TypeName& type); bool OnResume(const char* identifier); bool OnCreate(void); bool DeleteBlock(size_t index); void* AllocateInBlock(size_t index, size_t bytes, size_t alignment); bool CreateBlock(size_t index, size_t min_size); bool AttachBlock(size_t index); bool ResizeBlock(size_t index, const char* new_size); using SingletonMap = std::map, ShmAllocator>>; ChunkCache m_chunk_cache; SizeMap m_size_map; char m_magic[64]{}; PageHeap m_page_heap; uint64_t m_version = 0; size_t m_block_count = 0; SingletonMap* m_singletons{}; ShmOptions m_options; ShmBlock m_blocks[256]; }; } }