From a021e7a309a0c22538eff58730e8a8c816e5c84e Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 6 Dec 2022 16:41:22 +0100 Subject: [PATCH] Move make and destroy to luna --- kernel/src/memory/Heap.h | 12 ------------ luna/include/luna/Alloc.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 luna/include/luna/Alloc.h diff --git a/kernel/src/memory/Heap.h b/kernel/src/memory/Heap.h index 80d4b410..6e57f744 100644 --- a/kernel/src/memory/Heap.h +++ b/kernel/src/memory/Heap.h @@ -7,16 +7,4 @@ Result kcalloc(usize nmemb, usize size); Result krealloc(void* ptr, usize size); Result kfree(void* ptr); -template Result make() -{ - void* ptr = TRY(kcalloc(1, sizeof(T))); - return new (ptr) T; -} - -template Result destroy(T* item) -{ - item->~T(); - return kfree(item); -} - void dump_heap_usage(); \ No newline at end of file diff --git a/luna/include/luna/Alloc.h b/luna/include/luna/Alloc.h new file mode 100644 index 00000000..9985d363 --- /dev/null +++ b/luna/include/luna/Alloc.h @@ -0,0 +1,28 @@ +#pragma once +#include +#include +#include + +template Result make() +{ + T* const result = new T; + if (!result) return err(ENOMEM); + return result; +} + +template Result make_array(usize count) +{ + T* const result = new T[count]; + if (!result) return err(ENOMEM); + return result; +} + +template void destroy(T* item) +{ + delete item; +} + +template void destroy_array(T* item) +{ + delete[] item; +} \ No newline at end of file