From d2f3d029081122bd21146275317de88d69302e89 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 25 Nov 2019 03:19:22 +1100 Subject: pre-fill things allocated with operator new with 0xcd in debug builds (value can be changed by setting global g_mame_new_prefill_byte with a debugger) - this is gonna hurt performance, but it will help catch issues exposed when we remove pre-clearing before constructing devices --- src/lib/util/corealloc.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/lib/util/corealloc.cpp (limited to 'src/lib') diff --git a/src/lib/util/corealloc.cpp b/src/lib/util/corealloc.cpp new file mode 100644 index 00000000000..e3b7a458dbf --- /dev/null +++ b/src/lib/util/corealloc.cpp @@ -0,0 +1,34 @@ +// license:BSD-3-Clause +// copyright-holders:Vas Crabb +#include "corealloc.h" + +#include +#include +#include +#include + + +#ifdef MAME_DEBUG + +std::uint8_t g_mame_new_prefill_byte(0xcd); + +void *operator new(std::size_t n) +{ + void *const result(std::malloc(sz)); + if (ptr) + { + std::fill_n(reinterpret_cast(ptr), n, g_mame_new_prefill_byte); + return ptr; + } + else + { + throw std::bad_alloc(); + } +} + +void operator delete(void *ptr) noexcept +{ + std::free(ptr); +} + +#endif // MAME_DEBUG -- cgit v1.2.3