10 #include <mm_malloc.h>
15 template <
typename T,
typename... TArgs>
17 constexpr
Size size =
sizeof(T);
18 constexpr
Size alignment =
alignof(T);
19 void* ptr = _mm_malloc(size, alignment);
21 return new (ptr) T(std::forward<TArgs>(args)...);
38 return reinterpret_cast<std::size_t
>(std::addressof(value)) %
alignof(T) == 0;
52 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
55 template <
typename Type>
58 struct __attribute__((__may_alias__)) Holder {
59 alignas(Type)
char storage[
sizeof(Type)];
65 template <
typename... TArgs>
67 new (&holder) Type(std::forward<TArgs>(rest)...);
75 INLINE constexpr
operator Type&() noexcept {
80 INLINE constexpr
operator const Type&()
const noexcept {
86 return reinterpret_cast<Type&
>(holder);
91 return reinterpret_cast<const Type&
>(holder);
97 template <
typename Type>
106 template <
typename T>
114 INLINE constexpr
operator Type&() noexcept {
119 INLINE constexpr
operator const Type&()
const noexcept {
INLINE void alignedDelete(T *ptr)
Deletes an object previously allocated using alignedNew.
NAMESPACE_SPH_BEGIN INLINE T * alignedNew(TArgs &&... args)
Creates a new object of type T on heap, using aligned allocation.
INLINE bool isAligned(const T &value)
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
Few non-standard type traits.
constexpr INLINE const Type & get() const noexcept
Returns the reference to the stored value, const version.
INLINE void emplace(T &ref)
constexpr INLINE Type & get() noexcept
Return the reference to the stored value.
Simple block of memory on stack with size and alignment given by template type.
INLINE void emplace(TArgs &&... rest)
constexpr INLINE const Type & get() const noexcept
Returns the reference to the stored value, const version.
constexpr INLINE Type & get() noexcept
Return the reference to the stored value.