BAN: Move operator new/delete to BAN/Memory.cpp

We also now implement alignment new
This commit is contained in:
Bananymous 2023-01-10 21:59:40 +02:00
parent 64c57ea3d0
commit d02e3b19c7
3 changed files with 15 additions and 8 deletions

13
BAN/BAN/Memory.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <BAN/Memory.h>
namespace std { enum class align_val_t : size_t {}; }
void* operator new(size_t size) { return BAN::allocator(size); }
void* operator new[](size_t size) { return BAN::allocator(size); }
void* operator new(size_t size, std::align_val_t al) { return BAN::allocator_align(size, (size_t)al); }
void* operator new[](size_t size, std::align_val_t al) { return BAN::allocator_align(size, (size_t)al); }
void operator delete(void* addr) { BAN::deallocator(addr); }
void operator delete[](void* addr) { BAN::deallocator(addr); }
void operator delete(void* addr, size_t) { BAN::deallocator(addr); }
void operator delete[](void* addr, size_t) { BAN::deallocator(addr); }

View File

@ -33,6 +33,7 @@ FREEOBJS= \
$(ARCH_FREEOBJS) \ $(ARCH_FREEOBJS) \
BAN/String.o \ BAN/String.o \
BAN/StringView.o \ BAN/StringView.o \
BAN/Memory.o \
HOSTEDOBJS=\ HOSTEDOBJS=\
$(ARCH_HOSTEDOBJS) \ $(ARCH_HOSTEDOBJS) \

View File

@ -10,6 +10,7 @@ namespace BAN
{ {
#if defined(__is_kernel) #if defined(__is_kernel)
static constexpr void*(&allocator)(size_t) = kmalloc; static constexpr void*(&allocator)(size_t) = kmalloc;
static constexpr void*(&allocator_align)(size_t, size_t) = kmalloc;
static constexpr void(&deallocator)(void*) = kfree; static constexpr void(&deallocator)(void*) = kfree;
#else #else
static constexpr void*(&allocator)(size_t) = malloc; static constexpr void*(&allocator)(size_t) = malloc;
@ -36,11 +37,3 @@ namespace BAN
}; };
} }
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); }