summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/corealloc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/corealloc.cpp')
-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