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:
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
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) |
RAdoptAllocator & | operator= (const RAdoptAllocator &)=default |
RAdoptAllocator & | operator= (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>
using ROOT::Detail::VecOps::RAdoptAllocator< T >::const_pointer = typename StdAlloc_t::const_pointer |
Definition at line 60 of file RAdoptAllocator.hxx.
using ROOT::Detail::VecOps::RAdoptAllocator< T >::const_reference = typename StdAlloc_t::const_reference |
Definition at line 62 of file RAdoptAllocator.hxx.
using ROOT::Detail::VecOps::RAdoptAllocator< T >::difference_type = typename StdAlloc_t::difference_type |
Definition at line 64 of file RAdoptAllocator.hxx.
using ROOT::Detail::VecOps::RAdoptAllocator< T >::pointer = typename StdAlloc_t::pointer |
Definition at line 59 of file RAdoptAllocator.hxx.
using ROOT::Detail::VecOps::RAdoptAllocator< T >::propagate_on_container_move_assignment = std::true_type |
Definition at line 55 of file RAdoptAllocator.hxx.
using ROOT::Detail::VecOps::RAdoptAllocator< T >::propagate_on_container_swap = std::true_type |
Definition at line 56 of file RAdoptAllocator.hxx.
using ROOT::Detail::VecOps::RAdoptAllocator< T >::reference = typename StdAlloc_t::reference |
Definition at line 61 of file RAdoptAllocator.hxx.
using ROOT::Detail::VecOps::RAdoptAllocator< T >::size_type = typename StdAlloc_t::size_type |
Definition at line 63 of file RAdoptAllocator.hxx.
using ROOT::Detail::VecOps::RAdoptAllocator< T >::StdAlloc_t = std::allocator<T> |
Definition at line 57 of file RAdoptAllocator.hxx.
|
private |
Definition at line 72 of file RAdoptAllocator.hxx.
using ROOT::Detail::VecOps::RAdoptAllocator< T >::value_type = typename StdAlloc_t::value_type |
Definition at line 58 of file RAdoptAllocator.hxx.
|
strongprivate |
Enumerator | |
---|---|
kOwning | |
kAdopting | |
kAdoptingNoAllocYet |
Definition at line 71 of file RAdoptAllocator.hxx.
|
inline |
This is the constructor which allows the allocator to adopt a certain memory region.
Definition at line 79 of file RAdoptAllocator.hxx.
|
default |
|
default |
|
default |
ROOT::Detail::VecOps::RAdoptAllocator< T >::RAdoptAllocator | ( | const RAdoptAllocator< bool > & | o | ) |
Definition at line 204 of file RAdoptAllocator.hxx.
|
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.
|
inline |
Construct an object at a certain memory address.
U | The type of the memory address at which the object needs to be constructed |
Args | The arguments' types necessary for the construction of the object |
[in] | p | The memory address at which the object needs to be constructed |
[in] | args | The 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.
|
inline |
Dellocate some memory if that had not been adopted.
Definition at line 118 of file RAdoptAllocator.hxx.
|
inline |
Definition at line 125 of file RAdoptAllocator.hxx.
|
inline |
Definition at line 140 of file RAdoptAllocator.hxx.
|
inline |
Definition at line 138 of file RAdoptAllocator.hxx.
|
default |
|
default |
|
inline |
Definition at line 132 of file RAdoptAllocator.hxx.
|
friend |
Definition at line 204 of file RAdoptAllocator.hxx.
|
private |
Definition at line 74 of file RAdoptAllocator.hxx.
|
private |
Definition at line 73 of file RAdoptAllocator.hxx.
|
private |
Definition at line 75 of file RAdoptAllocator.hxx.