diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-03-02 11:59:47 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-03-02 11:59:47 +0100 |
| commit | b0d5c39d8acbd1429990e383ddd67226fc7bc0f9 (patch) | |
| tree | 0f4ad595859fc4c26460da258dca63c80970f7bb /src/memory.cc | |
| parent | a07e37de3f2b56b577da32b33d3dec45e0cd43b6 (diff) | |
working on source control
Diffstat (limited to 'src/memory.cc')
| -rw-r--r-- | src/memory.cc | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/memory.cc b/src/memory.cc index 518b761..2d83413 100644 --- a/src/memory.cc +++ b/src/memory.cc @@ -1,10 +1,12 @@ #ifndef MEMORY_CC #define MEMORY_CC -#include "common.cc" -#include <cstring> #include <mimalloc.h> +#include <cstring> + +#include "common.cc" + typedef u8* (*Allocator_Allocate)(u8* self, usize length, usize align); typedef void (*Allocator_Deallocate)(u8* self, u8* ptr); @@ -33,14 +35,15 @@ static inline void heap_deallocate(u8* self, u8* ptr) { } Allocator* heap_allocator() { - thread_local Allocator HEAP_ALLOCATOR = {nullptr, heap_allocate, heap_deallocate}; + thread_local Allocator HEAP_ALLOCATOR = {nullptr, heap_allocate, + heap_deallocate}; return &HEAP_ALLOCATOR; } -template<typename T> -bool slice_copy(Allocator* allocator, const Slice<T> *source, Slice<T> *out) { +template <typename T> +bool slice_copy(Allocator* allocator, const Slice<T>* source, Slice<T>* out) { T* new_ptr = allocate(allocator, source->size(), alignof(T)); - if(new_ptr == nullptr) return false; + if (new_ptr == nullptr) return false; memcpy((u8*)new_ptr, (u8*)source->ptr, source->length); @@ -49,9 +52,9 @@ bool slice_copy(Allocator* allocator, const Slice<T> *source, Slice<T> *out) { return true; } -template<typename T> -void slice_deallocate(Allocator* allocator, Slice<T> *slice) { - if(slice->ptr == nullptr) return; +template <typename T> +void slice_deallocate(Allocator* allocator, Slice<T>* slice) { + if (slice->ptr == nullptr) return; deallocate(allocator, (u8*)slice->ptr); @@ -60,4 +63,3 @@ void slice_deallocate(Allocator* allocator, Slice<T> *slice) { } #endif - |
