#include #include #include static const auto max_align_s = sizeof(std::max_align_t); void* operator new(size_t size) { void* p = std::malloc(size + max_align_s); if (p == nullptr) { throw std::bad_alloc{}; } char* begin = static_cast(p) + max_align_s; char* end = begin + size; std::uninitialized_fill(begin, end, 0x00); new (p) int64_t{ size }; return begin; } void operator delete(void* p) { if (p == nullptr) { return; } char* c = static_cast(p) - max_align_s; const uint64_t size = *reinterpret_cast(c); char* begin = static_cast(p); char* end = begin + size; std::uninitialized_fill(begin, end, 0xff); std::free(c); }