diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-02-17 00:21:48 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-02-17 22:29:50 +0100 |
commit | a141c401f78467bc15f62882fca5d55a007cacbb (patch) | |
tree | 908ac71a8640f78f45d22c6808c5fa6e373000fa /asl/allocator.cpp | |
parent | cb77cbe9ce4cddad6a460aa190ff70f0c13e4703 (diff) |
Reorganize everything
Diffstat (limited to 'asl/allocator.cpp')
-rw-r--r-- | asl/allocator.cpp | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/asl/allocator.cpp b/asl/allocator.cpp deleted file mode 100644 index 59bff76..0000000 --- a/asl/allocator.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "asl/allocator.hpp" -#include "asl/assert.hpp" -#include "asl/utility.hpp" -#include "asl/memory.hpp" -#include "asl/print.hpp" - -#include <cstdlib> - -// @Todo zalloc -// @Todo Cookies -// @Todo Debug values - -void* asl::GlobalHeap::alloc(const layout& layout) -{ -#if ASL_OS_WINDOWS - void* ptr = ::_aligned_malloc( - static_cast<size_t>(layout.size), - static_cast<size_t>(layout.align)); -#elif ASL_OS_LINUX - void* ptr = ::aligned_alloc( - static_cast<size_t>(layout.align), - static_cast<size_t>(layout.size)); -#endif - ASL_ASSERT(ptr != nullptr); // @Todo panic - return ptr; -} - -void* asl::GlobalHeap::realloc(void* old_ptr, [[maybe_unused]] const layout& old_layout, const layout& new_layout) -{ -#if ASL_OS_WINDOWS - return ::_aligned_realloc(old_ptr, - static_cast<size_t>(new_layout.size), - static_cast<size_t>(new_layout.align)); -#elif ASL_OS_LINUX - if (new_layout.align <= old_layout.align) - { - void* new_ptr = ::realloc(old_ptr, static_cast<size_t>(new_layout.size)); - ASL_ASSERT(new_ptr != nullptr); // @Todo panic - return new_ptr; - } - - void* new_ptr = alloc(new_layout); - asl::memcpy(new_ptr, old_ptr, asl::min(old_layout.size, new_layout.size)); - dealloc(old_ptr, old_layout); - return new_ptr; -#endif -} - -void asl::GlobalHeap::dealloc(void* ptr, const layout&) -{ -#if ASL_OS_WINDOWS - ::_aligned_free(ptr); -#elif ASL_OS_LINUX - ::free(ptr); -#endif -} |