diff options
author | 2020-10-03 14:31:39 +1000 | |
---|---|---|
committer | 2020-10-03 14:31:39 +1000 | |
commit | d1681a8ecef978ee34bafe24e95d34f25581e9c3 (patch) | |
tree | 958f96e617f2b5cb3c7c74536a14ad19d9a45be7 /src/lib/util/corealloc.h | |
parent | b7de847b6e5f259fa5c67b43951586204a6ae387 (diff) | |
parent | 9ac531e2b9aa690910cbeb35a14bd93fb001592b (diff) |
Merge remote-tracking branch 'upstream/master' into master
Diffstat (limited to 'src/lib/util/corealloc.h')
-rw-r--r-- | src/lib/util/corealloc.h | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/src/lib/util/corealloc.h b/src/lib/util/corealloc.h index 5d1f055e19b..db8aacf6cb2 100644 --- a/src/lib/util/corealloc.h +++ b/src/lib/util/corealloc.h @@ -8,54 +8,24 @@ ***************************************************************************/ -#pragma once - #ifndef MAME_LIB_UTIL_COREALLOC_H #define MAME_LIB_UTIL_COREALLOC_H -#include "osdcore.h" +#pragma once -#include <cstdlib> +#include "osdcore.h" #include <cstddef> +#include <cstdlib> #include <cstring> -#include <new> #include <memory> +#include <new> #include <type_traits> #include <utility> -//************************************************************************** -// MACROS -//************************************************************************** - -// global allocation helpers -- use these instead of new and delete -#define global_alloc(Type) new Type -#define global_alloc_array(Type, Num) new Type[Num] -#define global_free(Ptr) do { delete Ptr; } while (0) -#define global_free_array(Ptr) do { delete[] Ptr; } while (0) - - - -template<typename T, typename... Params> -inline T* global_alloc_clear(Params &&... args) -{ - void *const ptr = ::operator new(sizeof(T)); // allocate memory - std::memset(ptr, 0, sizeof(T)); - return new(ptr) T(std::forward<Params>(args)...); -} - -template<typename T> -inline T* global_alloc_array_clear(std::size_t num) -{ - auto const size = sizeof(T) * num; - void *const ptr = new unsigned char[size]; // allocate memory - std::memset(ptr, 0, size); - return new(ptr) T[num](); -} - - +// global allocation helpers template<typename Tp> struct MakeUniqClearT { typedef std::unique_ptr<Tp> single_object; }; |