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

This commit is contained in:
Vas Crabb 2019-11-25 03:19:22 +11:00
parent 29fa035d48
commit d2f3d02908
2 changed files with 35 additions and 0 deletions

View File

@ -47,6 +47,7 @@ project "utils"
MAME_DIR .. "src/lib/util/client_https.hpp",
MAME_DIR .. "src/lib/util/client_ws.hpp",
MAME_DIR .. "src/lib/util/client_wss.hpp",
MAME_DIR .. "src/lib/util/corealloc.cpp",
MAME_DIR .. "src/lib/util/corealloc.h",
MAME_DIR .. "src/lib/util/corefile.cpp",
MAME_DIR .. "src/lib/util/corefile.h",

View File

@ -0,0 +1,34 @@
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
#include "corealloc.h"
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <new>
#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<std::uint8_t volatile *>(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