Allocator used by the XML parser. The user can also use it.
More...
#include "nn/nlib/exi/ExiAllocator.h"
|
static bool | Test (size_t nbytes) noexcept |
| Tests whether nBytes of memory can be allocated. More...
|
|
static size_t | GetPos () noexcept |
| Returns the amount of memory that has already been allocated. More...
|
|
static bool | IsOutOfMemory () noexcept |
| Checks whether the previous attempt at memory allocation failed. More...
|
|
static ExiAllocatorEx | GetAllocator () noexcept |
| Returns the ExiAllocatorEx object for every thread.
|
|
|
static bool | Initialize (void *p, size_t size) noexcept |
| Initializes an allocator. More...
|
|
static void * | Finalize () noexcept |
| Finalizes allocator use. More...
|
|
static void | Reset () noexcept |
| Resets an allocator. Returns the allocator to the state it had immediately after initialization.
|
|
|
static void * | Alloc (size_t nbytes) noexcept |
| Allocates nBytes of memory from the allocator. More...
|
|
static 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...
|
|
static void | Dealloc (void *p) noexcept |
| Called when memory is deallocated. More...
|
|
Allocator used by the XML parser. The user can also use it.
- Description
- The XML parser runs within the memory range initially provided by the user. This practice helps prevent situations like overall system instability when invalid data (such as excessively long element names) is provided. You must initialize the allocator in separate memory regions for each thread. Within a particular thread, be careful when using functions such as
ExiAllocator::Reset
because memory is allocated for both the XML reader and the XML writer from the same memory space.
- Below is sample code for initialization and finalization.
Definition at line 56 of file ExiAllocator.h.
nn::nlib::exi::ExiAllocator::Alloc |
( |
size_t |
nbytes | ) |
|
|
staticnoexcept |
Allocates nBytes of memory from the allocator.
- Parameters
-
[in] | nbytes | Memory size to allocate. |
- Returns
- Address of the allocated memory.
NULL
if process fails.
nn::nlib::exi::ExiAllocator::Dealloc |
( |
void * |
p | ) |
|
|
staticnoexcept |
Called when memory is deallocated.
- Parameters
-
[in] | p | Starting address of the memory to deallocate. |
nn::nlib::exi::ExiAllocator::Finalize |
( |
| ) |
|
|
staticnoexcept |
Finalizes allocator use.
- Returns
- Pointer to the memory block that was provided during initialization.
- Description
- Finalizes allocator use and returns to the pre-initialization state. You must call this for each thread that uses the
exi
library.
nn::nlib::exi::ExiAllocator::GetPos |
( |
| ) |
|
|
staticnoexcept |
Returns the amount of memory that has already been allocated.
- Returns
- Amount of memory that has already been allocated.
nn::nlib::exi::ExiAllocator::Initialize |
( |
void * |
p, |
|
|
size_t |
size |
|
) |
| |
|
staticnoexcept |
Initializes an allocator.
- Parameters
-
[in] | p | Pointer to the start of the memory block. |
[in] | size | Memory block size. |
- Returns
- Returns
true
on success.
- Description
- Allocates memory to an allocator and initializes it. Memory must be allocated separately and initialized for each thread.
- The
exi
library runs using the memory that was allocated for each thread. Consequently, it is not possible to use the same XML parser instance from multiple threads.
nn::nlib::exi::ExiAllocator::IsOutOfMemory |
( |
| ) |
|
|
staticnoexcept |
Checks whether the previous attempt at memory allocation failed.
- Returns
- Returns
true
if memory allocation failed.
nn::nlib::exi::ExiAllocator::Realloc |
( |
void * |
ptr, |
|
|
size_t |
from_nbytes, |
|
|
size_t |
nbytes |
|
) |
| |
|
staticnoexcept |
Sometimes called when expanding the amount of memory that has been allocated.
- Parameters
-
[in] | ptr | Starting address of the memory to expand. |
[in] | from_nbytes | Memory size allocated prior to expansion. |
[in] | nbytes | Memory 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::ExiAllocator::Test |
( |
size_t |
nbytes | ) |
|
|
staticnoexcept |
Tests whether nBytes of memory can be allocated.
- Parameters
-
[in] | nbytes | Memory 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: