Logo ROOT  
Reference Guide
ROOT::Detail::VecOps::RAdoptAllocator< T > Class Template Reference

template<typename T>
class ROOT::Detail::VecOps::RAdoptAllocator< T >

RAdoptAllocator can provide a view on already allocated memory.

The RAdoptAllocator behaves like the standard allocator, and, as such, can be used to create stl containers. In addition, it behaves as if it allocated a certain memory region which is indeed not managed by it, but rather is "adopted". This is most useful to take advantage of widely adopted entities such as std::vector in a novel way, namely offering nice interfaces around an arbitrary memory region.

If memory is adopted, the first allocation returns the address of this memory region. For the subsequent allocations, the RAdoptAllocator behaves like a standard allocator.

For example:

std::vector<double> model {1, 2, 3};
unsigned int dummy;
RAdoptAllocator<double> alloc(model.data(), model.size());
std::vector<double, RAdoptAllocator<double>> v(model.size(), 0., alloc);
static RooMathCoreReg dummy

Now the vector v is ready to be used, de facto proxying the memory of the vector model. Upon a second allocation, the vector v ceases to be a proxy

v.emplace_back(0.);

now the vector v owns its memory as a regular vector.

Definition at line 51 of file RAdoptAllocator.hxx.

Classes

struct  rebind
 

Public Types

using const_pointer = typename StdAlloc_t::const_pointer
 
using const_reference = typename StdAlloc_t::const_reference
 
using difference_type = typename StdAlloc_t::difference_type
 
using pointer = typename StdAlloc_t::pointer
 
using propagate_on_container_move_assignment = std::true_type
 
using propagate_on_container_swap = std::true_type
 
using reference = typename StdAlloc_t::reference
 
using size_type = typename StdAlloc_t::size_type
 
using StdAlloc_t = std::allocator< T >
 
using value_type = typename StdAlloc_t::value_type
 

Public Member Functions

 RAdoptAllocator ()=default
 
 RAdoptAllocator (const RAdoptAllocator &)=default
 
 RAdoptAllocator (const RAdoptAllocator< bool > &)
 
 RAdoptAllocator (pointer p)
 This is the constructor which allows the allocator to adopt a certain memory region. More...
 
 RAdoptAllocator (RAdoptAllocator &&)=default
 
pointer allocate (std::size_t n)
 Allocate some memory If an address has been adopted, at the first call, that address is returned. More...
 
template<class U , class... Args>
void construct (U *p, Args &&... args)
 Construct an object at a certain memory address. More...
 
void deallocate (pointer p, std::size_t n)
 Dellocate some memory if that had not been adopted. More...
 
template<class U >
void destroy (U *p)
 
size_type max_size () const
 
bool operator!= (const RAdoptAllocator< T > &other)
 
RAdoptAllocatoroperator= (const RAdoptAllocator &)=default
 
RAdoptAllocatoroperator= (RAdoptAllocator &&)=default
 
bool operator== (const RAdoptAllocator< T > &other)
 

Private Types

enum class  EAllocType : char { kOwning , kAdopting , kAdoptingNoAllocYet }
 
using StdAllocTraits_t = std::allocator_traits< StdAlloc_t >
 

Private Attributes

EAllocType fAllocType = EAllocType::kOwning
 
pointer fInitialAddress = nullptr
 
StdAlloc_t fStdAllocator
 

Friends

class RAdoptAllocator< bool >
 

#include <ROOT/RAdoptAllocator.hxx>

Member Typedef Documentation

◆ const_pointer

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::const_pointer = typename StdAlloc_t::const_pointer

Definition at line 60 of file RAdoptAllocator.hxx.

◆ const_reference

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::const_reference = typename StdAlloc_t::const_reference

Definition at line 62 of file RAdoptAllocator.hxx.

◆ difference_type

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::difference_type = typename StdAlloc_t::difference_type

Definition at line 64 of file RAdoptAllocator.hxx.

◆ pointer

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::pointer = typename StdAlloc_t::pointer

Definition at line 59 of file RAdoptAllocator.hxx.

◆ propagate_on_container_move_assignment

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::propagate_on_container_move_assignment = std::true_type

Definition at line 55 of file RAdoptAllocator.hxx.

◆ propagate_on_container_swap

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::propagate_on_container_swap = std::true_type

Definition at line 56 of file RAdoptAllocator.hxx.

◆ reference

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::reference = typename StdAlloc_t::reference

Definition at line 61 of file RAdoptAllocator.hxx.

◆ size_type

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::size_type = typename StdAlloc_t::size_type

Definition at line 63 of file RAdoptAllocator.hxx.

◆ StdAlloc_t

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::StdAlloc_t = std::allocator<T>

Definition at line 57 of file RAdoptAllocator.hxx.

◆ StdAllocTraits_t

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::StdAllocTraits_t = std::allocator_traits<StdAlloc_t>
private

Definition at line 72 of file RAdoptAllocator.hxx.

◆ value_type

template<typename T >
using ROOT::Detail::VecOps::RAdoptAllocator< T >::value_type = typename StdAlloc_t::value_type

Definition at line 58 of file RAdoptAllocator.hxx.

Member Enumeration Documentation

◆ EAllocType

template<typename T >
enum class ROOT::Detail::VecOps::RAdoptAllocator::EAllocType : char
strongprivate
Enumerator
kOwning 
kAdopting 
kAdoptingNoAllocYet 

Definition at line 71 of file RAdoptAllocator.hxx.

Constructor & Destructor Documentation

◆ RAdoptAllocator() [1/5]

template<typename T >
ROOT::Detail::VecOps::RAdoptAllocator< T >::RAdoptAllocator ( pointer  p)
inline

This is the constructor which allows the allocator to adopt a certain memory region.

Definition at line 79 of file RAdoptAllocator.hxx.

◆ RAdoptAllocator() [2/5]

template<typename T >
ROOT::Detail::VecOps::RAdoptAllocator< T >::RAdoptAllocator ( )
default

◆ RAdoptAllocator() [3/5]

template<typename T >
ROOT::Detail::VecOps::RAdoptAllocator< T >::RAdoptAllocator ( const RAdoptAllocator< T > &  )
default

◆ RAdoptAllocator() [4/5]

template<typename T >
ROOT::Detail::VecOps::RAdoptAllocator< T >::RAdoptAllocator ( RAdoptAllocator< T > &&  )
default

◆ RAdoptAllocator() [5/5]

template<typename T >
ROOT::Detail::VecOps::RAdoptAllocator< T >::RAdoptAllocator ( const RAdoptAllocator< bool > &  o)

Definition at line 204 of file RAdoptAllocator.hxx.

Member Function Documentation

◆ allocate()

template<typename T >
pointer ROOT::Detail::VecOps::RAdoptAllocator< T >::allocate ( std::size_t  n)
inline

Allocate some memory If an address has been adopted, at the first call, that address is returned.

Subsequent calls will make "decay" the allocator to a regular stl allocator.

Definition at line 105 of file RAdoptAllocator.hxx.

◆ construct()

template<typename T >
template<class U , class... Args>
void ROOT::Detail::VecOps::RAdoptAllocator< T >::construct ( U *  p,
Args &&...  args 
)
inline

Construct an object at a certain memory address.

Template Parameters
UThe type of the memory address at which the object needs to be constructed
ArgsThe arguments' types necessary for the construction of the object
Parameters
[in]pThe memory address at which the object needs to be constructed
[in]argsThe arguments necessary for the construction of the object This method is a no op if memory has been adopted.

Definition at line 94 of file RAdoptAllocator.hxx.

◆ deallocate()

template<typename T >
void ROOT::Detail::VecOps::RAdoptAllocator< T >::deallocate ( pointer  p,
std::size_t  n 
)
inline

Dellocate some memory if that had not been adopted.

Definition at line 118 of file RAdoptAllocator.hxx.

◆ destroy()

template<typename T >
template<class U >
void ROOT::Detail::VecOps::RAdoptAllocator< T >::destroy ( U *  p)
inline

Definition at line 125 of file RAdoptAllocator.hxx.

◆ max_size()

template<typename T >
size_type ROOT::Detail::VecOps::RAdoptAllocator< T >::max_size ( ) const
inline

Definition at line 140 of file RAdoptAllocator.hxx.

◆ operator!=()

template<typename T >
bool ROOT::Detail::VecOps::RAdoptAllocator< T >::operator!= ( const RAdoptAllocator< T > &  other)
inline

Definition at line 138 of file RAdoptAllocator.hxx.

◆ operator=() [1/2]

template<typename T >
RAdoptAllocator & ROOT::Detail::VecOps::RAdoptAllocator< T >::operator= ( const RAdoptAllocator< T > &  )
default

◆ operator=() [2/2]

template<typename T >
RAdoptAllocator & ROOT::Detail::VecOps::RAdoptAllocator< T >::operator= ( RAdoptAllocator< T > &&  )
default

◆ operator==()

template<typename T >
bool ROOT::Detail::VecOps::RAdoptAllocator< T >::operator== ( const RAdoptAllocator< T > &  other)
inline

Definition at line 132 of file RAdoptAllocator.hxx.

Friends And Related Function Documentation

◆ RAdoptAllocator< bool >

template<typename T >
friend class RAdoptAllocator< bool >
friend

Definition at line 204 of file RAdoptAllocator.hxx.

Member Data Documentation

◆ fAllocType

template<typename T >
EAllocType ROOT::Detail::VecOps::RAdoptAllocator< T >::fAllocType = EAllocType::kOwning
private

Definition at line 74 of file RAdoptAllocator.hxx.

◆ fInitialAddress

template<typename T >
pointer ROOT::Detail::VecOps::RAdoptAllocator< T >::fInitialAddress = nullptr
private

Definition at line 73 of file RAdoptAllocator.hxx.

◆ fStdAllocator

template<typename T >
StdAlloc_t ROOT::Detail::VecOps::RAdoptAllocator< T >::fStdAllocator
private

Definition at line 75 of file RAdoptAllocator.hxx.


The documentation for this class was generated from the following file: