diff --git a/src/Utils/Utils/MemoryManager.cpp b/src/Utils/Utils/MemoryManager.cpp index 2943b525..94993729 100644 --- a/src/Utils/Utils/MemoryManager.cpp +++ b/src/Utils/Utils/MemoryManager.cpp @@ -26,9 +26,9 @@ MemoryManager::~MemoryManager() m_destructible.clear(); } -void* MemoryManager::Alloc(const size_t size) +void* MemoryManager::AllocRaw(const size_t size) { - void* result = malloc(size); + void* result = calloc(size, 1u); m_allocations.push_back(result); return result; @@ -46,7 +46,7 @@ char* MemoryManager::Dup(const char* str) return result; } -void MemoryManager::Free(void* data) +void MemoryManager::Free(const void* data) { for (auto iAlloc = m_allocations.begin(); iAlloc != m_allocations.end(); ++iAlloc) { @@ -59,7 +59,7 @@ void MemoryManager::Free(void* data) } } -void MemoryManager::Delete(void* data) +void MemoryManager::Delete(const void* data) { for (auto iAlloc = m_destructible.begin(); iAlloc != m_destructible.end(); ++iAlloc) { diff --git a/src/Utils/Utils/MemoryManager.h b/src/Utils/Utils/MemoryManager.h index 505fa14a..bc26f1ee 100644 --- a/src/Utils/Utils/MemoryManager.h +++ b/src/Utils/Utils/MemoryManager.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include class MemoryManager @@ -8,7 +9,12 @@ class MemoryManager class IDestructible { public: + IDestructible() = default; virtual ~IDestructible() = default; + IDestructible(const IDestructible& other) = default; + IDestructible(IDestructible&& other) noexcept = default; + IDestructible& operator=(const IDestructible& other) = default; + IDestructible& operator=(IDestructible&& other) noexcept = default; }; template class Allocation final : public IDestructible @@ -16,9 +22,9 @@ class MemoryManager public: T m_entry; - template - explicit Allocation(_Valty&&... _Val) - : m_entry(std::forward<_Valty>(_Val)...) + template + explicit Allocation(ValType&&... val) + : m_entry(std::forward(val)...) { } @@ -45,17 +51,26 @@ class MemoryManager public: MemoryManager(); virtual ~MemoryManager(); + MemoryManager(const MemoryManager& other) = delete; + MemoryManager(MemoryManager&& other) noexcept = default; + MemoryManager& operator=(const MemoryManager& other) = delete; + MemoryManager& operator=(MemoryManager&& other) noexcept = default; - void* Alloc(size_t size); + void* AllocRaw(size_t size); char* Dup(const char* str); - template T* Create(_Valty&&... _Val) + template std::add_pointer_t Alloc(const size_t count = 1u) { - Allocation* allocation = new Allocation(std::forward<_Valty>(_Val)...); + return static_cast>(AllocRaw(sizeof(T) * count)); + } + + template std::add_pointer_t Create(ValType&&... val) + { + Allocation* allocation = new Allocation(std::forward(val)...); m_destructible.emplace_back(allocation, &allocation->m_entry); return &allocation->m_entry; } - void Free(void* data); - void Delete(void* data); + void Free(const void* data); + void Delete(const void* data); };