summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/corealloc.cpp
blob: eb6ebe80b372190bc1bd465db5231b2bdf049fa9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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(n));
	if (result)
	{
		std::fill_n(reinterpret_cast<std::uint8_t volatile *>(result), n, g_mame_new_prefill_byte);
		return result;
	}
	else
	{
		throw std::bad_alloc();
	}
}

void operator delete(void *ptr) noexcept
{
	std::free(ptr);
}

#endif // MAME_DEBUG