5namespace Stroika::Foundation::Memory {
13 inline void* BlockAllocationUseHelper<T>::operator
new ([[maybe_unused]]
size_t n)
15 Require (n ==
sizeof (T));
16 return BlockAllocator<T>{}.allocate (1);
19 inline void* BlockAllocationUseHelper<T>::operator
new ([[maybe_unused]]
size_t n, int,
const char*, int)
21 Require (n ==
sizeof (T));
22 return BlockAllocator<T>{}.allocate (1);
25 inline void BlockAllocationUseHelper<T>::operator
delete (
void* p)
27 BlockAllocator<T>{}.deallocate (
reinterpret_cast<T*
> (p), 1);
30 inline void BlockAllocationUseHelper<T>::operator
delete (
void* p, int,
const char*, int)
32 BlockAllocator<T>{}.deallocate (
reinterpret_cast<T*
> (p), 1);
41 constexpr bool UsesBlockAllocation ()
43 return derived_from<T, BlockAllocationUseHelper<T>>;
51 template <
typename T,
typename... ARGS_TYPE>
54 if constexpr (UsesBlockAllocation<T> ()) {
58 return make_shared<T> (forward<ARGS_TYPE> (args)...);
68 inline void* BlockAllocationUseGlobalAllocatorHelper<T>::operator
new (
size_t n)
70 return ::operator
new (n);
73 inline void* BlockAllocationUseGlobalAllocatorHelper<T>::operator
new (
size_t n, int,
const char*, int)
75 return ::operator
new (n);
78 inline void BlockAllocationUseGlobalAllocatorHelper<T>::operator
delete (
void* p)
80 ::operator
delete (p);
83 inline void BlockAllocationUseGlobalAllocatorHelper<T>::operator
delete (
void* p, int,
const char*, int)
85 ::operator
delete (p);
94 template <
typename... ARGS>
95 inline T* ManuallyBlockAllocated<T>::New (ARGS&&... args)
97#if qStroika_Foundation_Memory_PreferBlockAllocation
98 return new (BlockAllocator<T>{}.allocate (1)) T{forward<ARGS> (args)...};
100 return new T{forward<ARGS> (args)...};
103 template <
typename T>
104 inline void ManuallyBlockAllocated<T>::Delete (T* p)
noexcept
106#if qStroika_Foundation_Memory_PreferBlockAllocation
109 BlockAllocator<T>{}.deallocate (p, 1);
auto MakeSharedPtr(ARGS_TYPE &&... args) -> shared_ptr< T >
same as make_shared, but if type T has block allocation, then use block allocation for the 'shared pa...