summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
authorGravatarGravatar Vas Crabb <vas@vastheman.com>2019-11-25 03:19:22 +1100
committerGravatarGravatar Vas Crabb <vas@vastheman.com>2019-11-25 03:20:08 +1100
commitd2f3d029081122bd21146275317de88d69302e89 (patch)
tree8d7248a0248bb8952c95e620f2d4aad6ecfdb38b /src/lib
parent29fa035d484daf24be42ca50e57257cc639b7165 (diff)
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
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util/corealloc.cpp34
1 files changed, 34 insertions, 0 deletions
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 <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