BAN: BAN/Memory.h now provides the operator new and delete
This commit is contained in:
parent
c6467b8ebc
commit
85068e27d6
|
@ -15,4 +15,32 @@ namespace BAN
|
|||
static constexpr auto& allocator = malloc;
|
||||
static constexpr auto& deallocator = free;
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
class OwnPtr
|
||||
{
|
||||
public:
|
||||
template<typename... Args>
|
||||
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); }
|
|
@ -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); }
|
Loading…
Reference in New Issue