From 74933654160064f9303551a6c012be6b88d5b626 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Mon, 2 Mar 2026 12:29:14 +0100 Subject: creating and removing buffer --- src/memory.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/memory.cc') 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 -bool slice_copy(Allocator* allocator, const Slice* source, Slice* out) { +bool slice_copy(const Allocator* allocator, const Slice* source, Slice* 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* source, Slice* out) { } template -void slice_deallocate(Allocator* allocator, Slice* slice) { +void slice_deallocate(const Allocator* allocator, Slice* slice) { if (slice->ptr == nullptr) return; deallocate(allocator, (u8*)slice->ptr); -- cgit v1.2.3