diff options
Diffstat (limited to 'deimos/core/allocator.cpp')
-rw-r--r-- | deimos/core/allocator.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/deimos/core/allocator.cpp b/deimos/core/allocator.cpp new file mode 100644 index 0000000..a525bfd --- /dev/null +++ b/deimos/core/allocator.cpp @@ -0,0 +1,55 @@ +#include "deimos/core/allocator.h"
+
+#include <cstdlib>
+
+namespace deimos
+{
+
+class SystemAllocatorImpl : public IAllocator
+{
+public:
+ SystemAllocatorImpl() : IAllocator(MemoryScope{0}) {}
+
+ void* Reallocate(
+ void* old_ptr, int64 /* old_size */, int64 new_size,
+ const char* /* file */, int32 /* line */) override
+ {
+ if (old_ptr == nullptr)
+ {
+ return new_size > 0 ? ::malloc((uint64)new_size) : nullptr;
+ }
+
+ if (new_size == 0)
+ {
+ if (old_ptr != nullptr)
+ {
+ ::free(old_ptr);
+ }
+ }
+ else
+ {
+ return ::realloc(old_ptr, (uint64)new_size);
+ }
+ return nullptr;
+ }
+};
+
+class AllocatorApiImpl : public AllocatorApi
+{
+ SystemAllocatorImpl m_system_impl;
+
+public:
+ AllocatorApiImpl()
+ {
+ system = &m_system_impl;
+ }
+};
+
+AllocatorApi* BootstrapAllocatorApi()
+{
+ static AllocatorApiImpl g_instance{};
+ return &g_instance;
+}
+
+} // namespace deimos
+
|