From cf7db48c261ee9c896c813a38ff8c59da5b8fe07 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sun, 26 Jan 2025 00:40:51 +0100 Subject: Fix line endings --- asl/allocator.cpp | 112 +++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 56 deletions(-) (limited to 'asl/allocator.cpp') diff --git a/asl/allocator.cpp b/asl/allocator.cpp index 5dbdce0..59bff76 100644 --- a/asl/allocator.cpp +++ b/asl/allocator.cpp @@ -1,56 +1,56 @@ -#include "asl/allocator.hpp" -#include "asl/assert.hpp" -#include "asl/utility.hpp" -#include "asl/memory.hpp" -#include "asl/print.hpp" - -#include - -// @Todo zalloc -// @Todo Cookies -// @Todo Debug values - -void* asl::GlobalHeap::alloc(const layout& layout) -{ -#if ASL_OS_WINDOWS - void* ptr = ::_aligned_malloc( - static_cast(layout.size), - static_cast(layout.align)); -#elif ASL_OS_LINUX - void* ptr = ::aligned_alloc( - static_cast(layout.align), - static_cast(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(new_layout.size), - static_cast(new_layout.align)); -#elif ASL_OS_LINUX - if (new_layout.align <= old_layout.align) - { - void* new_ptr = ::realloc(old_ptr, static_cast(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 -} +#include "asl/allocator.hpp" +#include "asl/assert.hpp" +#include "asl/utility.hpp" +#include "asl/memory.hpp" +#include "asl/print.hpp" + +#include + +// @Todo zalloc +// @Todo Cookies +// @Todo Debug values + +void* asl::GlobalHeap::alloc(const layout& layout) +{ +#if ASL_OS_WINDOWS + void* ptr = ::_aligned_malloc( + static_cast(layout.size), + static_cast(layout.align)); +#elif ASL_OS_LINUX + void* ptr = ::aligned_alloc( + static_cast(layout.align), + static_cast(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(new_layout.size), + static_cast(new_layout.align)); +#elif ASL_OS_LINUX + if (new_layout.align <= old_layout.align) + { + void* new_ptr = ::realloc(old_ptr, static_cast(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 +} -- cgit