From b0d5c39d8acbd1429990e383ddd67226fc7bc0f9 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Mon, 2 Mar 2026 11:59:47 +0100 Subject: working on source control --- src/memory.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/memory.cc') 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 #include +#include + +#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 -bool slice_copy(Allocator* allocator, const Slice *source, Slice *out) { +template +bool slice_copy(Allocator* allocator, const Slice* source, Slice* 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 *source, Slice *out) { return true; } -template -void slice_deallocate(Allocator* allocator, Slice *slice) { - if(slice->ptr == nullptr) return; +template +void slice_deallocate(Allocator* allocator, Slice* slice) { + if (slice->ptr == nullptr) return; deallocate(allocator, (u8*)slice->ptr); @@ -60,4 +63,3 @@ void slice_deallocate(Allocator* allocator, Slice *slice) { } #endif - -- cgit v1.2.3