Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
BlockAllocated.h File Reference
#include "Stroika/Foundation/StroikaPreComp.h"
#include "Stroika/Foundation/Common/Empty.h"
#include "Stroika/Foundation/Memory/BlockAllocator.h"
#include "BlockAllocated.inl"

Go to the source code of this file.

Classes

struct  Stroika::Foundation::Memory::BlockAllocationUseHelper< T >
 
struct  Stroika::Foundation::Memory::BlockAllocationUseGlobalAllocatorHelper< T >
 
struct  Stroika::Foundation::Memory::InheritAndUseBlockAllocationIfAppropriate< DERIVED, BASE_REP, andTrueCheck >
 
class  Stroika::Foundation::Memory::ManuallyBlockAllocated< T >
 ManuallyBlockAllocated<T> is a simple wrapper on BlockAllocator<T>. If qStroika_Foundation_Memory_PreferBlockAllocation defined, this will use block allocation for a given type - at a given call. More...
 

Namespaces

namespace  Stroika::Foundation
 

Macros

#define qStroika_Foundation_Memory_PreferBlockAllocation   1
 Allow use of block-allocation in classes which uses DECLARE_USE_BLOCK_ALLOCATION(), or UseBlockAllocationIfAppropriate etc.
 

Typedefs

template<typename T , bool andTrueCheck = true>
using Stroika::Foundation::Memory::UseBlockAllocationIfAppropriate = conditional_t< qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocationUseHelper< T >, Common::Empty >
 Use this to enable block allocation for a particular class. Beware of subclassing.
 
template<typename T , bool andTrueCheck = true>
using Stroika::Foundation::Memory::BlockAllocatorOrStdAllocatorAsAppropriate = conditional_t< qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocator< T >, std::allocator< T > >
 for type T, either use BlockAllocator<T>, or std::allocator
 

Functions

template<typename T , typename... ARGS_TYPE>
auto Stroika::Foundation::Memory::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 part' of T as well.
 

Detailed Description

Note
Code-Status: Beta

The reason for this option is for better use in templates like LinkedList<> - where we might want to blockallocate for small sizes of T, but not for ALL.

Definition in file BlockAllocated.h.

Macro Definition Documentation

◆ qStroika_Foundation_Memory_PreferBlockAllocation

#define qStroika_Foundation_Memory_PreferBlockAllocation   1

Allow use of block-allocation in classes which uses DECLARE_USE_BLOCK_ALLOCATION(), or UseBlockAllocationIfAppropriate etc.

Allow use of block-allocation. The main reason to disable it indiscriminately is for debugging purposes (looking for memory leaks). But others may have other reasons.

Defaults to 1

Definition at line 40 of file BlockAllocated.h.

Typedef Documentation

◆ UseBlockAllocationIfAppropriate

template<typename T , bool andTrueCheck = true>
using Stroika::Foundation::Memory::UseBlockAllocationIfAppropriate = typedef conditional_t<qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocationUseHelper<T>, Common::Empty>

Use this to enable block allocation for a particular class. Beware of subclassing.

This utility class can be used to avoid some of the C++ gorp required in declaring that you are using block-allocation with a given class.

Example Usage:
struct MyIterRep_ : Iterator<Character>::IRep, public Memory::UseBlockAllocationIfAppropriate<MyIterRep_> {
_SharedPtrIRep fStr; // effectively RO, since if anyone modifies, our copy will remain unchanged
size_t fCurIdx;
MyIterRep_ (const _SharedPtrIRep& r, size_t idx = 0)
: fStr{r}
, fCurIdx{idx}
{
Require (fCurIdx <= fStr->_GetLength ());
}
...
};

If qStroika_Foundation_Memory_PreferBlockAllocation true (default) - this will use the optimized block allocation store, but if qStroika_Foundation_Memory_PreferBlockAllocation is false (0), this will just default to the global ::new/::delete

See also
Stroika::Foundation::Memory::BlockAllocationUseHelper
Stroika::Foundation::Memory::BlockAllocator
Stroika::Foundation::Memory::AutomaticallyBlockAllocated
Stroika::Foundation::Memory::ManuallyBlockAllocated

Definition at line 130 of file BlockAllocated.h.

◆ BlockAllocatorOrStdAllocatorAsAppropriate

template<typename T , bool andTrueCheck = true>
using Stroika::Foundation::Memory::BlockAllocatorOrStdAllocatorAsAppropriate = typedef conditional_t<qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocator<T>, std::allocator<T> >

for type T, either use BlockAllocator<T>, or std::allocator

Note
If using this, allocate shared_ptr<T> with Memory::MakeSharedPtr.

Definition at line 198 of file BlockAllocated.h.

Function Documentation

◆ MakeSharedPtr()

template<typename T , typename... ARGS_TYPE>
auto Stroika::Foundation::Memory::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 part' of T as well.

Note
this is helpful for shared_ptr (performance), but not for unique_ptr<>.

Definition at line 52 of file BlockAllocated.inl.