From 85068e27d6c7b5b5430e31c3509741679264edc1 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 10 Jan 2023 17:51:33 +0200 Subject: [PATCH] BAN: BAN/Memory.h now provides the operator new and delete --- BAN/include/BAN/Memory.h | 30 +++++++++++++++++++++++++++++- kernel/include/kernel/kmalloc.h | 9 --------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/BAN/include/BAN/Memory.h b/BAN/include/BAN/Memory.h index 367dcf9b81..9643cd1645 100644 --- a/BAN/include/BAN/Memory.h +++ b/BAN/include/BAN/Memory.h @@ -15,4 +15,32 @@ namespace BAN static constexpr auto& allocator = malloc; static constexpr auto& deallocator = free; #endif -} \ No newline at end of file + + template + class OwnPtr + { + public: + template + OwnPtr(const Args&... args) + { + m_pointer = new T(args...); + } + + ~OwnPtr() + { + delete m_pointer; + } + + private: + T* m_pointer = nullptr; + }; + +} + +inline void* operator new(size_t size) { return BAN::allocator(size); } +inline void* operator new[](size_t size) { return BAN::allocator(size); } + +inline void operator delete(void* addr) { BAN::deallocator(addr); } +inline void operator delete[](void* addr) { BAN::deallocator(addr); } +inline void operator delete(void* addr, size_t) { BAN::deallocator(addr); } +inline void operator delete[](void* addr, size_t) { BAN::deallocator(addr); } \ No newline at end of file diff --git a/kernel/include/kernel/kmalloc.h b/kernel/include/kernel/kmalloc.h index fdadebfaa6..9e678918d4 100644 --- a/kernel/include/kernel/kmalloc.h +++ b/kernel/include/kernel/kmalloc.h @@ -8,12 +8,3 @@ void kmalloc_dump_nodes(); void* kmalloc_eternal(size_t); void* kmalloc(size_t); void kfree(void*); - - -inline void* operator new(size_t size) { return kmalloc(size); } -inline void* operator new[](size_t size) { return kmalloc(size); } - -inline void operator delete(void* addr) { kfree(addr); } -inline void operator delete[](void* addr) { kfree(addr); } -inline void operator delete(void* addr, size_t) { kfree(addr); } -inline void operator delete[](void* addr, size_t) { kfree(addr); } \ No newline at end of file