25#ifdef JPL_COMPILER_MSVC
33#include <memory_resource>
61 std::pmr::memory_resource* mPrevious;
68 template<
class T,
class AllocatorType = std::allocator<T>>
72 using Traits = std::allocator_traits<AForT>;
91 Traits::destroy(mAllocator,
ptr);
92 Traits::deallocate(mAllocator,
ptr, 1);
107 using Traits = std::allocator_traits<Allocator>;
127 static_assert(std::is_move_assignable_v<PmrDeleter<int>>);
131 template<
class Allocator>
132 inline constexpr bool is_pmr_alloc_v =
135 std::pmr::polymorphic_allocator<std::byte>
143 template<
class T,
class Allocator,
class...
Args>
146 using AForT =
typename std::allocator_traits<Allocator>::template
rebind_alloc<T>;
147 using Traits = std::allocator_traits<AForT>;
150 T* raw = Traits::allocate(
rebound, 1);
152 if constexpr (std::is_nothrow_constructible_v<T,
Args...>)
154 Traits::construct(
rebound, raw, std::forward<Args>(
args)...);
160 Traits::construct(
rebound, raw, std::forward<Args>(
args)...);
163 Traits::deallocate(
rebound, raw, 1);
168 if constexpr (Internal::is_pmr_alloc_v<std::remove_cvref_t<Allocator>>)
185 template<
class T = std::
byte>
190 template<
class T,
class ...Args>
205 template<
class T,
class...
Args>
220 template<
class T,
class Y>
236 template<
class T,
class...
Args>
273 return this == &
other;
289 return std::malloc(
inSize);
307#if defined(JPL_PLATFORM_WINDOWS)
311 void*
block =
nullptr;
323#if defined(JPL_PLATFORM_WINDOWS)
356 return this == &
other;
#define JPL_DEFAULT_NEW_ALIGNMENT
Definition Core.h:357
#define JPL_GCC_SUPPRESS_WARNING(w)
Definition Core.h:283
#define JPL_CLANG_SUPPRESS_WARNING(w)
Definition Core.h:272
#define JPL_ASSERT(inExpression,...)
Main assert macro, usage: JPL_ASSERT(condition, message) or JPL_ASSERT(condition)
Definition ErrorReporting.h:76
std::size_t MaxUsage
Definition Memory.h:279
CountingResource(std::pmr::memory_resource *upstream)
Definition Memory.h:249
std::pmr::memory_resource * Upstream
Definition Memory.h:277
std::size_t InUse
Definition Memory.h:278
static JPL_INLINE void * Allocate(std::size_t inSize)
Definition Memory.h:286
static JPL_INLINE void AlignedFree(void *inBlock)
Definition Memory.h:321
static JPL_INLINE void Free(void *inBlock)
Definition Memory.h:298
static JPL_INLINE void * AlignedAllocate(std::size_t inSize, std::size_t inAlignment)
Definition Memory.h:303
static JPL_INLINE void * Reallocate(void *inBlock, std::size_t inOldSize, std::size_t inNewSize)
Definition Memory.h:292
std::pmr::polymorphic_allocator< T > Allocator
Definition Memory.h:106
JPL_INLINE void operator()(T *p) noexcept
Definition Memory.h:115
std::allocator_traits< Allocator > Traits
Definition Memory.h:107
PmrDeleter(std::pmr::memory_resource *resource) noexcept
Definition Memory.h:110
PmrMallocResource()=default
RAII override library-wide default memory resource.
Definition Memory.h:47
ScopedGlobalMemoryResource(std::pmr::memory_resource *resource)
Definition Memory.h:49
~ScopedGlobalMemoryResource()
Definition Memory.h:55
Definition AcousticMaterial.h:36
JPL_INLINE T * DefaultNew(Args &&...args)
Allocate new object from deafult global memory resource used in JPLSpatial.
Definition Memory.h:191
JPL_INLINE void reset_pmr_shared(std::shared_ptr< T > &sharedPtr, Y *ptr)
Definition Memory.h:221
JPL_INLINE std::shared_ptr< T > make_pmr_shared(Args &&... args)
std::make_shared wrapper using our global memory resource
Definition Memory.h:206
std::unique_ptr< T, PmrDeleter< T > > pmr_unique_ptr
Alias for unique ptr using pmr allocator and deleter.
Definition Memory.h:233
JPL_INLINE void DefaultDelete(T *object)
Delete object allcoated from deafult global memory resource. The object must had been allocated by ca...
Definition Memory.h:198
std::pmr::memory_resource * GetDefaultMemoryResource() noexcept
Definition Memory.h:42
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813
std::pmr::memory_resource * gDefaultMemoryResource
Definition Memory.h:41
std::pmr::polymorphic_allocator< T > PmrAllocator
Just a shorter alias.
Definition Memory.h:183
auto allocate_unique(const Allocator &allocator, Args &&... args)
Definition Memory.h:144
JPL_INLINE PmrAllocator< T > GetDefaultPmrAllocator()
Definition Memory.h:186
JPL_INLINE pmr_unique_ptr< T > make_pmr_unique(Args &&... args)
std::make_unique wrapper using our global memory resource
Definition Memory.h:237
Definition ChannelMap.h:268
typename std::allocator_traits< AllocatorType >::template rebind_alloc< T > AForT
Definition Memory.h:71
AllocatorDeleter() noexcept(std::is_nothrow_default_constructible_v< AForT >)=default
JPL_INLINE void operator()(T *ptr) noexcept
Definition Memory.h:87
std::allocator_traits< AForT > Traits
Definition Memory.h:72
AllocatorDeleter(const AForT &allcoator) noexcept(std::is_nothrow_copy_constructible_v< AForT >)
Definition Memory.h:82