summaryrefslogtreecommitdiff
path: root/src/memory.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/memory.cc')
-rw-r--r--src/memory.cc22
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
-