Implement operator new/delete
This commit is contained in:
parent
81b3ae244c
commit
bc462433ed
42
new.cpp
Normal file
42
new.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "new.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
[[nodiscard]] void *operator new(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void operator delete(void *ptr) noexcept
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
void operator delete(void *ptr, size_t) noexcept
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
[[nodiscard]] void *operator new[](size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void operator delete[](void *ptr) noexcept
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
void operator delete[](void *ptr, size_t) noexcept
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
[[nodiscard]] void *operator new(size_t, void *ptr) noexcept
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
[[nodiscard]] void *operator new[](size_t, void *ptr) noexcept
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
void operator delete(void *, void *)noexcept {}
|
||||
void operator delete[](void *, void *) noexcept {}
|
18
new.hpp
Normal file
18
new.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
[[nodiscard]] void *operator new(size_t size);
|
||||
|
||||
void operator delete(void *ptr) noexcept;
|
||||
void operator delete(void *ptr, size_t size) noexcept;
|
||||
|
||||
[[nodiscard]] void *operator new[](size_t size);
|
||||
|
||||
void operator delete[](void *ptr) noexcept;
|
||||
void operator delete[](void *ptr, size_t size) noexcept;
|
||||
|
||||
[[nodiscard]] void *operator new(size_t size, void *ptr) noexcept;
|
||||
[[nodiscard]] void *operator new[](size_t size, void *ptr) noexcept;
|
||||
void operator delete(void *ptr, void *)noexcept;
|
||||
void operator delete[](void *ptr, void *) noexcept;
|
Loading…
Reference in New Issue
Block a user