diff options
author | 2016-03-21 08:27:06 +0100 | |
---|---|---|
committer | 2016-03-21 08:27:06 +0100 | |
commit | a99df788017c2bf5a56034d4f9152bf8ab95a168 (patch) | |
tree | 3beec27b413c75b8f9f88199519e45fd07959bf8 /src/lib/util/corealloc.h | |
parent | b224d9a77ad6483daf2b60b75dbdc323a3bcd4b0 (diff) | |
parent | 3afd990226a2c647290579bebb5537bd0fd3faac (diff) |
Merge with master
Diffstat (limited to 'src/lib/util/corealloc.h')
-rw-r--r-- | src/lib/util/corealloc.h | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/lib/util/corealloc.h b/src/lib/util/corealloc.h index 2c1df6dd46c..b5fc126cba5 100644 --- a/src/lib/util/corealloc.h +++ b/src/lib/util/corealloc.h @@ -10,15 +10,20 @@ #pragma once -#ifndef __COREALLOC_H__ -#define __COREALLOC_H__ +#ifndef MAME_LIB_UTIL_COREALLOC_H +#define MAME_LIB_UTIL_COREALLOC_H + +#include "osdcore.h" #include <stdlib.h> + +#include <cstddef> +#include <cstring> #include <new> +#include <memory> #include <type_traits> #include <utility> -#include <memory> -#include "osdcore.h" + //************************************************************************** @@ -35,21 +40,21 @@ -template<typename _Tp, typename... _Args> -inline _Tp* global_alloc_clear(_Args&&... __args) +template<typename T, typename... Params> +inline T* global_alloc_clear(Params &&... args) { - unsigned char * ptr = new unsigned char[sizeof(_Tp)]; // allocate memory - memset(ptr, 0, sizeof(_Tp)); - return new(ptr) _Tp(std::forward<_Args>(__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 _Tp> -inline _Tp* global_alloc_array_clear(size_t __num) +template<typename T> +inline T* global_alloc_array_clear(std::size_t num) { - auto size = sizeof(_Tp) * __num; - unsigned char* ptr = new unsigned char[size]; // allocate memory - memset(ptr, 0, size); - return new(ptr) _Tp[__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](); } @@ -104,4 +109,4 @@ inline typename _MakeUniqClear<_Tp>::__array make_unique_clear(size_t __num) template<typename _Tp, typename... _Args> inline typename _MakeUniqClear<_Tp>::__invalid_type make_unique_clear(_Args&&...) = delete; -#endif /* __COREALLOC_H__ */ +#endif // MAME_LIB_UTIL_COREALLOC_H |