nlib
nn::nlib::exi::ExiAllocatorEx Class Referencefinal

Allocator that can be set for each instance of XmlStreamReader and XmlStreamWriter. More...

#include "nn/nlib/exi/ExiAllocator.h"

Public Member Functions

bool Test (size_t nbytes) noexcept
 Tests whether nBytes of memory can be allocated. More...
 
size_t GetPos () noexcept
 Returns the amount of memory that has already been allocated. More...
 
bool IsOutOfMemory () noexcept
 Checks whether the previous attempt at memory allocation failed. More...
 
bool IsValid () const noexcept
 Returns true if the allocator has been initialized.
 
 operator bool () const
 Returns true if the allocator has been initialized.
 
Basic Member Functions
constexpr ExiAllocatorEx () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~ExiAllocatorEx () noexcept
 Destructor.
 
 ExiAllocatorEx (const ExiAllocatorEx &rhs) noexcept
 Copy constructor.
 
ExiAllocatorExoperator= (const ExiAllocatorEx &rhs) noexcept
 Assignment operator.
 
ExiAllocatorExassign (ExiAllocatorEx &rhs, move_tag)
 Assigns the object by using swap for a move.
 
 ExiAllocatorEx (ExiAllocatorEx &rhs, move_tag)
 Instantiates the object by using swap for a move.
 
 ExiAllocatorEx (ExiAllocatorEx &&rhs)
 Instantiates the object (move constructor). This function is useful when using C++11.
 
ExiAllocatorExoperator= (ExiAllocatorEx &&rhs)
 Move assignment operator. This function is useful when using C++11.
 
void swap (ExiAllocatorEx &rhs) noexcept
 Swaps the contents of an object.
 
Initialization and Finalization
bool Initialize (void *p, size_t size) noexcept
 Initializes an allocator. More...
 
void * Finalize () noexcept
 Finalizes allocator use. More...
 
void Reset () noexcept
 Resets an allocator. Returns the allocator to the state it had immediately after initialization.
 
Memory Allocation and Deallocation
void * Alloc (size_t nbytes) noexcept
 Allocates nBytes of memory from the allocator. More...
 
void * Realloc (void *ptr, size_t from_nbytes, size_t nbytes) noexcept
 Sometimes called when expanding the amount of memory that has been allocated. More...
 
void Dealloc (void *p) noexcept
 Called when memory is deallocated. More...
 

Detailed Description

Allocator that can be set for each instance of XmlStreamReader and XmlStreamWriter.

Description
ExiAllocator is a singleton, but ExiAllocatorEx can create instances. By passing arguments to XmlStreamReader and XmlStreamWriter, different allocators can be used for each instance (even within the same thread).
The same member functions are implemented as ExiAllocator. Sample usage is shown below.
al_writer.Initialize(g_WriterBuf, BUF_SIZE);
OutputStream* os = ....;
// Pass ExiAllocatorEx as the second or third argument to the Create method.
UniquePtr<XmlStreamWriter> w(XmlStreamWriter::Create(os, al));

Definition at line 22 of file ExiAllocator.h.

Member Function Documentation

nn::nlib::exi::ExiAllocatorEx::Alloc ( size_t  nbytes)
noexcept

Allocates nBytes of memory from the allocator.

Parameters
[in]nbytesMemory size to allocate.
Returns
Address of the allocated memory. NULL if process fails.
nn::nlib::exi::ExiAllocatorEx::Dealloc ( void *  p)
noexcept

Called when memory is deallocated.

Parameters
[in]pStarting address of the memory to deallocate.
nn::nlib::exi::ExiAllocatorEx::Finalize ( )
noexcept

Finalizes allocator use.

Returns
Pointer to the memory block that was provided during initialization.
nn::nlib::exi::ExiAllocatorEx::GetPos ( )
noexcept

Returns the amount of memory that has already been allocated.

Returns
Amount of memory that has already been allocated.
nn::nlib::exi::ExiAllocatorEx::Initialize ( void *  p,
size_t  size 
)
noexcept

Initializes an allocator.

Parameters
[in]pPointer to the start of the memory block.
[in]sizeMemory block size.
Returns
Returns true on success.
Description
Allocates memory to an allocator and initializes it.
nn::nlib::exi::ExiAllocatorEx::IsOutOfMemory ( )
noexcept

Checks whether the previous attempt at memory allocation failed.

Returns
Returns true if memory allocation failed.
nn::nlib::exi::ExiAllocatorEx::Realloc ( void *  ptr,
size_t  from_nbytes,
size_t  nbytes 
)
noexcept

Sometimes called when expanding the amount of memory that has been allocated.

Parameters
[in]ptrStarting address of the memory to expand.
[in]from_nbytesMemory size allocated prior to expansion.
[in]nbytesMemory size after expansion.
Returns
Address of the allocated memory. NULL if process fails.
Description
Unlike with the standard C realloc function, pass this function the amount of memory currently allocated.
nn::nlib::exi::ExiAllocatorEx::Test ( size_t  nbytes)
noexcept

Tests whether nBytes of memory can be allocated.

Parameters
[in]nbytesMemory size to attempt to allocate.
Returns
Returns false if allocation is not possible.
Description
If it returns false, the subsequent call to IsOutOfMemory() returns true. Used to determine in advance whether Alloc() will fail.

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