nlib
nn::nlib::heap::CentralHeap Class Referencefinal

Central heap class whose use is paired with CachedHeap. It is used to implement nmalloc. More...

#include "nn/nlib/heap/CentralHeap.h"

Public Member Functions

void * Alloc (size_t n) noexcept
 Allocates a memory block. More...
 
void * Alloc (size_t n, size_t algn) noexcept
 Allocates a memory block with a specific alignment. More...
 
errno_t Free (void *p) noexcept
 Frees memory. More...
 
bool IsClean () noexcept
 Checks whether the current heap status is the same as the status immediately after initialization, including metadata. More...
 
void CalcHeapHash (HeapHash *hash) noexcept
 For more information, see nmalloc_heaphash. More...
 
void DumpEx (NMallocDumpMode mode, nlib_fd fd) const noexcept
 For details, see nmalloc_dumpex2. More...
 
void DumpEx (NMallocDumpMode mode) const noexcept
 For more information, see nmalloc_dumpex. More...
 
void Dump () const noexcept
 Runs DumpEx(NMALLOC_DUMP_BASIC, 1).
 
errno_t WalkAllocatedPtrs (nmalloc_heapwalk_callback func, void *user_ptr) noexcept
 For more information, see nmalloc_walk_allocated_ptrs.
 
Basic Member Functions
 CentralHeap () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~CentralHeap () noexcept
 Destructor.
 
Initialization and Finalization
errno_t Initialize (void *start, size_t size, uint32_t heap_option) noexcept
 Initializes the heap. More...
 
void Finalize () noexcept
 Finalizes use of the heap and changes the object's status to what it was prior to initialization.
 
bool MakeCache (CachedHeap *ptr) noexcept
 Initializes CachedHeap and associates it with this CentralHeap. More...
 

Static Public Attributes

static const size_t kPageSize
 Page size of the heap (not related to the operating system page size).
 

Detailed Description

Central heap class whose use is paired with CachedHeap. It is used to implement nmalloc.

Description
It can be used to create CachedHeap instances (thread-specific heaps). CachedHeap allocates memory from and returns memory to the central heap. Memory allocation and freeing by user applications are generally performed using CachedHeap. Memory can also be allocated directly from the CentralHeap, however, this decreases efficiency.

Definition at line 18 of file CentralHeap.h.

Member Function Documentation

nn::nlib::heap::CentralHeap::Alloc ( size_t  n)
inlinenoexcept

Allocates a memory block.

Parameters
[in]nSpecifies the memory block size.
Returns
Returns the pointer for the allocated memory. NULL if process fails.

Definition at line 30 of file CentralHeap.h.

nn::nlib::heap::CentralHeap::Alloc ( size_t  n,
size_t  algn 
)
noexcept

Allocates a memory block with a specific alignment.

Parameters
[in]nSpecifies the memory block size.
[in]algnSpecifies the alignment.
Returns
Returns the pointer for the allocated memory. NULL if process fails.
The alignment must be a power of two.
nn::nlib::heap::CentralHeap::CalcHeapHash ( HeapHash hash)
noexcept

For more information, see nmalloc_heaphash.

Parameters
[out]hashSpecifies the pointer where the hash values are stored.
nn::nlib::heap::CentralHeap::DumpEx ( NMallocDumpMode  mode,
nlib_fd  fd 
) const
noexcept

For details, see nmalloc_dumpex2.

Parameters
[in]modeSpecifies the display options.
[in]fdSpecifies the file descriptor to display. Specifying 1 indicates standard output.
nn::nlib::heap::CentralHeap::DumpEx ( NMallocDumpMode  mode) const
inlinenoexcept

For more information, see nmalloc_dumpex.

Parameters
[in]modeSpecifies the display options.

Definition at line 38 of file CentralHeap.h.

nn::nlib::heap::CentralHeap::Free ( void *  p)
noexcept

Frees memory.

Parameters
[in]pSpecifies a pointer to the memory block to free.
Returns
Returns 0 on success. Any nonzero value indicates that an error has occurred (for example, the pointer wasn't in the heap).
nn::nlib::heap::CentralHeap::Initialize ( void *  start,
size_t  size,
uint32_t  heap_option 
)
noexcept

Initializes the heap.

Parameters
[in]startSpecifies a pointer to the beginning of the heap.
[in]sizeSpecifies the size of the heap. It must be a multiple of kPageSize.
[in]heap_optionSpecifies the heap-instantiation options. See NMallocSettings::heap_option.
Returns
0 Indicates that initialization was successful. Any other return value indicates failure.
Description
If a start is not aligned to kPageSize, the region is truncated to the memory boundary before use.
nn::nlib::heap::CentralHeap::IsClean ( )
noexcept

Checks whether the current heap status is the same as the status immediately after initialization, including metadata.

Returns
Returns true if the same as the heap status immediately following initialization.
Description
For more information, see nmalloc_isclean.
nn::nlib::heap::CentralHeap::MakeCache ( CachedHeap ptr)
noexcept

Initializes CachedHeap and associates it with this CentralHeap.

Parameters
[out]ptrSpecifies a pointer to the CachedHeap object to initialize.
Returns
Returns true on success.
Description
When this function is called, the central heap allocates a cache region and associates itself with CachedHeap. Thereafter, memory can be allocated and freed using CachedHeap.

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