diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-03-02 12:29:14 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-03-02 12:29:14 +0100 |
| commit | 74933654160064f9303551a6c012be6b88d5b626 (patch) | |
| tree | 95191a4335f1a59a407cde9cba010a6c59ebab41 /src/memory.cc | |
| parent | df736f5a97b329377e45adb8d734fd58ea9b14ac (diff) | |
creating and removing buffer
Diffstat (limited to 'src/memory.cc')
| -rw-r--r-- | src/memory.cc | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/memory.cc b/src/memory.cc index 2d83413..1cb6cb9 100644 --- a/src/memory.cc +++ b/src/memory.cc @@ -16,11 +16,11 @@ struct Allocator { Allocator_Deallocate deallocate; }; -u8* allocate(Allocator* allocator, usize size, usize align) { +u8* allocate(const Allocator* allocator, usize size, usize align) { return allocator->allocate(allocator->self, size, align); } -void deallocate(Allocator* allocator, u8* ptr) { +void deallocate(const Allocator* allocator, u8* ptr) { allocator->deallocate(allocator->self, ptr); } @@ -34,14 +34,14 @@ static inline void heap_deallocate(u8* self, u8* ptr) { mi_free(ptr); } -Allocator* heap_allocator() { +const Allocator* heap_allocator() { 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) { +bool slice_copy(const Allocator* allocator, const Slice<T>* source, Slice<T>* out) { T* new_ptr = allocate(allocator, source->size(), alignof(T)); if (new_ptr == nullptr) return false; @@ -53,7 +53,7 @@ bool slice_copy(Allocator* allocator, const Slice<T>* source, Slice<T>* out) { } template <typename T> -void slice_deallocate(Allocator* allocator, Slice<T>* slice) { +void slice_deallocate(const Allocator* allocator, Slice<T>* slice) { if (slice->ptr == nullptr) return; deallocate(allocator, (u8*)slice->ptr); |
