#include "deimos/core/allocator.h" #include namespace deimos { class SystemAllocatorImpl : public IAllocator { public: gsl::owner Reallocate( gsl::owner old_ptr, int64_t /* old_size */, int64_t new_size, MemoryScope /* scope */, const SourceLocation& /* source_location */) override { if (old_ptr == nullptr) { return new_size > 0 ? ::malloc((uint64_t)new_size) : nullptr; } if (new_size == 0) { if (old_ptr != nullptr) { ::free(old_ptr); } } else { return ::realloc(old_ptr, (uint64_t)new_size); } return nullptr; } }; class AllocatorApiImpl : public AllocatorApi { SystemAllocatorImpl m_system_impl; Allocator m_system; public: constexpr AllocatorApiImpl() : m_system{ &m_system_impl, {0} } { system = &m_system; } gsl::owner CreateChild(Allocator* parent, gsl::czstring /* description */) override { return parent->New(parent->allocator(), MemoryScope{}); } void DestroyChild(gsl::owner allocator) override { deimos_StaticAssert(std::is_trivially_destructible_v); allocator->Delete(allocator); } }; AllocatorApi* BootstrapAllocatorApi() { static constinit AllocatorApiImpl g_instance{}; return &g_instance; } } // namespace deimos