xentara-plugin v2.0.4
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::memory::MemoryBlock< RawMemory > Class Referencefinal

A raw memory block. More...

#include <xentara/memory/RawMemoryBlock.hpp>

+ Inheritance diagram for xentara::memory::MemoryBlock< RawMemory >:

Public Types

using Handle = RawMemoryHandle
 A handle for accessing the block.
 

Public Member Functions

 MemoryBlock () noexcept=default
 Default constructor.
 
 MemoryBlock (std::nullptr_t) noexcept
 Conversion from an null pointer.
 
 MemoryBlock (MemoryBlock &&other) noexcept
 Move constructor.
 
 ~MemoryBlock ()
 Destructor.
 
auto operator= (MemoryBlock &&other) noexcept -> MemoryBlock &
 Move assignment operator.
 
auto operator= (std::nullptr_t) noexcept -> MemoryBlock &
 Assignment operator for a null pointer.
 
auto operator== (std::nullptr_t) const -> bool
 Comparison operator with a null pointer.
 
 operator bool () const noexcept
 Boolean operator.
 
auto create (MemoryResource &memoryResource, std::reference_wrapper< const MemoryResource::BlockHandler > handler) -> Initializer< RawMemory >
 Creates the block.
 
auto destroy () noexcept -> void
 Destroys any allocated data and turns the block into a null block.
 
auto initializer () -> Initializer< RawMemory >
 Recovers the initializer for additional initialization.
 
auto handle (std::size_t offset=0) const noexcept -> Handle
 Returns the memory handle into the block's memory.
 
auto memoryResource () const noexcept -> MemoryResource &
 Returns the memory resource that the block was allocated in.
 
auto blockHandle () const noexcept -> const MemoryResource::BlockHandle &
 Returns an handle for the block containing the data.
 

Detailed Description

A raw memory block.

This class can be moved but not copied.

Member Typedef Documentation

◆ Handle

A handle for accessing the block.

Constructor & Destructor Documentation

◆ MemoryBlock() [1/3]

xentara::memory::MemoryBlock< RawMemory >::MemoryBlock ( )
defaultnoexcept

Default constructor.

This constructor constructs a null object without an allocated block

◆ MemoryBlock() [2/3]

xentara::memory::MemoryBlock< RawMemory >::MemoryBlock ( std::nullptr_t  )
noexcept

Conversion from an null pointer.

This constructor constructs a null object without an allocated block

◆ MemoryBlock() [3/3]

xentara::memory::MemoryBlock< RawMemory >::MemoryBlock ( MemoryBlock< RawMemory > &&  other)
noexcept

Move constructor.

This constructor transfers any allocated memory from other to this object. other is turned into as a null object without an allocated block.

◆ ~MemoryBlock()

Destructor.

Deallocates any allocated memory

Member Function Documentation

◆ blockHandle()

auto xentara::memory::MemoryBlock< RawMemory >::blockHandle ( ) const -> const MemoryResource::BlockHandle &
noexcept

Returns an handle for the block containing the data.

◆ create()

Creates the block.

Any previously allocated memory is deallocated

Parameters
memoryResourceThe memory resource to use
handlerThe handler for the block. Must remain valid until destroy() is called.
Returns
An accessor object for the allocated memory that you can use to initialize it

◆ destroy()

auto xentara::memory::MemoryBlock< RawMemory >::destroy ( ) -> void
noexcept

Destroys any allocated data and turns the block into a null block.

Like operator new and std::free(), this method can safely be called on null objects.

◆ handle()

auto xentara::memory::MemoryBlock< RawMemory >::handle ( std::size_t  offset = 0) const -> Handle
noexcept

Returns the memory handle into the block's memory.

Parameters
offsetThe offset from the beginning of the block's data
Returns
A handle pointing to the desired offset within the block's data

◆ initializer()

Recovers the initializer for additional initialization.

This function can be used to perform additional initialization of the memory from code locations where the initializer returned from allocate() is not available.

Attention
Do not call this function if any read or write sentinels may exist for the block, or if anyone may be holding any read handles or write handles to data within the block.
Returns
An initializer for additional initialization of the block's memory

◆ memoryResource()

auto xentara::memory::MemoryBlock< RawMemory >::memoryResource ( ) const -> MemoryResource &
noexcept

Returns the memory resource that the block was allocated in.

This function may not be called on null objects with no allocated block

◆ operator bool()

xentara::memory::MemoryBlock< RawMemory >::operator bool ( ) const
explicitnoexcept

Boolean operator.

This operator checks whether the object has an allocated memory block

◆ operator=() [1/2]

auto xentara::memory::MemoryBlock< RawMemory >::operator= ( MemoryBlock< RawMemory > &&  other) -> MemoryBlock &
noexcept

Move assignment operator.

This operator swaps the allocated memory with other.

◆ operator=() [2/2]

auto xentara::memory::MemoryBlock< RawMemory >::operator= ( std::nullptr_t  ) -> MemoryBlock &
noexcept

Assignment operator for a null pointer.

This operator deallocates any allocated data turns the object into a null object.

◆ operator==()

auto xentara::memory::MemoryBlock< RawMemory >::operator== ( std::nullptr_t  ) const -> bool

Comparison operator with a null pointer.

This operator checks whether the object is a null object without an allocated block