4#ifndef _Stroika_Foundation_Memory_BlockAllocated_h_
5#define _Stroika_Foundation_Memory_BlockAllocated_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
11#include "Stroika/Foundation/Common/Concepts.h"
42#ifndef qStroika_Foundation_Memory_PreferBlockAllocation
43#define qStroika_Foundation_Memory_PreferBlockAllocation 1
46namespace Stroika::Foundation::Memory {
73 static void*
operator new (
size_t n);
74 static void*
operator new (
size_t n, int,
const char*, int);
75 static void operator delete (
void* p);
76 static void operator delete (
void* p, int,
const char*, int);
82 constexpr bool UsesBlockAllocation ();
90 template <
typename T,
typename... ARGS_TYPE>
98 static void*
operator new (
size_t n);
99 static void*
operator new (
size_t n, int,
const char*, int);
100 static void operator delete (
void* p);
101 static void operator delete (
void* p, int,
const char*, int);
133 template <
typename T,
bool andTrueCheck = true>
135 conditional_t<qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocationUseHelper<T>,
Common::Empty>;
151 template <
typename DERIVED, Common::ClassNotFinal BASE_REP,
bool andTrueCheck = true>
153 template <
typename... ARGS>
155 : BASE_REP{forward<ARGS> (args)...}
158 static void*
operator new (
size_t n)
160 if constexpr (andTrueCheck) {
164 return BASE_REP::operator
new (n);
167 static void*
operator new (
size_t n,
int a,
const char* b,
int c)
169 if constexpr (andTrueCheck) {
173 return BASE_REP::operator
new (n, a, b, c);
176 static void operator delete (
void* p)
178 if constexpr (andTrueCheck) {
182 return BASE_REP::operator
delete (p);
185 static void operator delete (
void* p,
int a,
const char* b,
int c)
187 if constexpr (andTrueCheck) {
191 return BASE_REP::operator
delete (p, a, b, c);
201 template <
typename T,
bool andTrueCheck = true>
203 conditional_t<qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocator<T>, std::allocator<T>>;
215 template <
typename T>
220 template <
typename... ARGS>
221 static T* New (ARGS&&... args);
226 static void Delete (T* p)
noexcept;
236#include "BlockAllocated.inl"
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...
conditional_t< qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocator< T >, std::allocator< T > > BlockAllocatorOrStdAllocatorAsAppropriate
for type T, either use BlockAllocator<T>, or std::allocator
conditional_t< qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocationUseHelper< T >, Common::Empty > UseBlockAllocationIfAppropriate
Use this to enable block allocation for a particular class. Beware of subclassing.
ManuallyBlockAllocated<T> is a simple wrapper on BlockAllocator<T>. If qStroika_Foundation_Memory_Pre...