Documentation of memory

( foonathan/memory)

joint_ptr< T, RawAllocator, Mutex > Class Template Reference

Detailed Description

template<typename T, class RawAllocator, class Mutex>
class foonathan::memory::joint_ptr< T, RawAllocator, Mutex >

A pointer to an object where all allocations are joint.

It can either own an object or not (be nullptr). When it owns an object, it points to a memory block. This memory block contains both the actual object (of the type T) and space for allocations of Ts members.

The type T must be derived from joint_type and every constructor must take joint as first parameter. This prevents that you create joint objects yourself, without the additional storage. The default copy and move constructors are also deleted, you need to write them yourself.

You can only access the object through the pointer, use joint_allocator or joint_array as members of T, to enable the memory sharing. If you are using joint_allocator inside STL containers, make sure that you do not call their regular copy/move constructors, but instead the version where you pass an allocator.

The memory block will be managed by the given RawAllocator, it is stored in an allocator_reference and not owned by the pointer directly.

Typedefs

using element_type = T
 
using allocator_type = typename allocator_reference< RawAllocator, Mutex >::allocator_type
 
using mutex = Mutex
 

Member Functions

 joint_ptr (joint_ptr &&other) noexcept
 
 ~joint_ptr () noexcept
 
joint_ptroperator= (joint_ptr &&other) noexcept
 
joint_ptroperator= (std::nullptr_t) noexcept
 
void reset () noexcept
 
 operator bool () const noexcept
 
element_type & operator* () const noexcept
 
element_type * operator-> () const noexcept
 
element_type * get () const noexcept
 
auto get_allocator () const noexcept -> decltype(std::declval< allocator_reference< allocator_type, mutex >>().get_allocator())
 
 joint_ptr (allocator_type &alloc) noexcept
 
 joint_ptr (const allocator_type &alloc) noexcept
 
template<typename... Args>
 joint_ptr (allocator_type &alloc, joint_size additional_size, Args &&... args)
 
template<typename... Args>
 joint_ptr (const allocator_type &alloc, joint_size additional_size, Args &&... args)
 

Constructors

§ joint_ptr() [1/5]

joint_ptr ( allocator_type &  alloc)
explicitnoexcept
Effects:
Creates it with a RawAllocator, but does not own a new object.

§ joint_ptr() [2/5]

joint_ptr ( const allocator_type &  alloc)
explicitnoexcept
Effects:
Creates it with a RawAllocator, but does not own a new object.

§ joint_ptr() [3/5]

joint_ptr ( allocator_type &  alloc,
joint_size  additional_size,
Args &&...  args 
)
Effects:
Reserves memory for the object and the additional size, and creates the object by forwarding the arguments to its constructor. The RawAllocator will be used for the allocation.

§ joint_ptr() [4/5]

joint_ptr ( const allocator_type &  alloc,
joint_size  additional_size,
Args &&...  args 
)
Effects:
Reserves memory for the object and the additional size, and creates the object by forwarding the arguments to its constructor. The RawAllocator will be used for the allocation.

§ joint_ptr() [5/5]

joint_ptr ( joint_ptr< T, RawAllocator, Mutex > &&  other)
noexcept
Effects:
Move-constructs the pointer. Ownership will be transferred from other to the new object.

§ ~joint_ptr()

~joint_ptr ( )
noexcept
Effects:
Destroys the object and deallocates its storage.

Member Functions

§ operator=() [1/2]

joint_ptr& operator= ( joint_ptr< T, RawAllocator, Mutex > &&  other)
noexcept
Effects:
Move-assings the pointer. The previously owned object will be destroyed, and ownership of other transferred.

§ operator=() [2/2]

joint_ptr& operator= ( std::nullptr_t  )
noexcept
Effects:
Same as reset().

§ reset()

void reset ( )
noexcept
Effects:
Destroys the object it refers to, if there is any.

§ operator bool()

operator bool ( ) const
explicitnoexcept
Returns:
true if the pointer does own an object, false otherwise.

§ operator*()

element_type& operator* ( ) const
noexcept
Returns:
A reference to the object it owns.
Requires:
The pointer must own an object, i.e. operator bool() must return true.

§ operator->()

element_type* operator-> ( ) const
noexcept
Returns:
A pointer to the object it owns.
Requires:
The pointer must own an object, i.e. operator bool() must return true.

§ get()

element_type* get ( ) const
noexcept
Returns:
A pointer to the object it owns or nullptr, if it does not own any object.

§ get_allocator()

auto get_allocator ( ) const -> decltype( std::declval<allocator_reference<allocator_type, mutex>>().get_allocator())
noexcept
Returns:
A reference to the allocator it will use for the deallocation.

Related Functions

§ swap

void swap ( joint_ptr< T, RawAllocator, Mutex > &  a,
joint_ptr< T, RawAllocator, Mutex > &  b 
)
friend
Effects:
Swaps to pointers and their ownership and allocator.