memory: add all kinds of C++ new/delete operators
This commit is contained in:
parent
78314c25fb
commit
c504b5dc31
@ -57,4 +57,22 @@ bool operator!=(const kAllocator<T> &, const kAllocator<U> &) {
|
||||
// operators new and delete only call kMalloc/kFree, so C++ code
|
||||
// must stay after paging setup
|
||||
void *operator new(std::size_t size);
|
||||
void operator delete(void *ptr) noexcept;
|
||||
void *operator new[](std::size_t size);
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
void *operator new(std::size_t size, std::align_val_t align);
|
||||
void *operator new[](std::size_t size, std::align_val_t align);
|
||||
#endif
|
||||
|
||||
void operator delete(void *ptr) noexcept;
|
||||
void operator delete[](void *ptr) noexcept;
|
||||
#if __cplusplus >= 201402L
|
||||
void operator delete(void *ptr, std::size_t size) noexcept;
|
||||
void operator delete[](void *ptr, std::size_t size) noexcept;
|
||||
#endif
|
||||
#if __cplusplus >= 201703L
|
||||
void operator delete(void *ptr, std::align_val_t align) noexcept;
|
||||
void operator delete[](void *ptr, std::align_val_t align) noexcept;
|
||||
void operator delete(void *ptr, std::size_t size, std::align_val_t align) noexcept;
|
||||
void operator delete[](void *ptr, std::size_t size, std::align_val_t align) noexcept;
|
||||
#endif
|
||||
|
@ -1,13 +1,27 @@
|
||||
#include "memory.h"
|
||||
#include "memory.hpp"
|
||||
|
||||
void *operator new(std::size_t size) {
|
||||
void *data = kMalloc(size);
|
||||
/*if (!data) {
|
||||
throw helos::bad_alloc();
|
||||
}*/
|
||||
return data;
|
||||
}
|
||||
#include "../extlib/dlmalloc/malloc-2.8.6.h"
|
||||
|
||||
void operator delete(void *ptr) noexcept {
|
||||
kFree(ptr);
|
||||
}
|
||||
void *operator new(std::size_t size) { return kMalloc(size); }
|
||||
void *operator new[](std::size_t size) { return kMalloc(size); }
|
||||
|
||||
void operator delete(void *ptr) noexcept { kFree(ptr); }
|
||||
void operator delete[](void *ptr) noexcept { kFree(ptr); }
|
||||
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
void *operator new(std::size_t size, std::align_val_t align) { return dlmemalign((size_t)align, size); }
|
||||
void *operator new[](std::size_t size, std::align_val_t align) { return dlmemalign((size_t)align, size); }
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201402L
|
||||
void operator delete(void *ptr, std::size_t size) noexcept { kFree(ptr); }
|
||||
void operator delete[](void *ptr, std::size_t size) noexcept { kFree(ptr); }
|
||||
#endif
|
||||
#if __cplusplus >= 201703L
|
||||
void operator delete(void *ptr, std::align_val_t align) noexcept { kFree(ptr); }
|
||||
void operator delete[](void *ptr, std::align_val_t align) noexcept { kFree(ptr); }
|
||||
void operator delete(void *ptr, std::size_t size, std::align_val_t align) noexcept { kFree(ptr); }
|
||||
void operator delete[](void *ptr, std::size_t size, std::align_val_t align) noexcept { kFree(ptr); }
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user