mirror of
https://github.com/holub/mame
synced 2025-04-19 07:00:31 +03:00
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:
parent
29fa035d48
commit
d2f3d02908
@ -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",
|
||||
|
34
src/lib/util/corealloc.cpp
Normal file
34
src/lib/util/corealloc.cpp
Normal 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
|
Loading…
Reference in New Issue
Block a user