virtmem
virtual memory library for Arduino
|
Base template class for virtual memory allocators. More...
#include <alloc.h>
Classes | |
struct | TVPtr |
Generalized shortcut to virtual pointer type linked to this allocator. More... | |
Public Types | |
template<typename T > | |
using | VPtr = virtmem::VPtr< T, Derived > |
Public Member Functions | |
template<typename T > | |
VPtr< T, Derived > | alloc (VPtrSize size=sizeof(T)) |
Allocates memory from the linked virtual memory allocator. More... | |
template<typename T > | |
void | free (VPtr< T, Derived > &p) |
Frees a block of virtual memory. More... | |
template<typename T > | |
VPtr< T, Derived > | newClass (VPtrSize size=sizeof(T)) |
Allocates memory and constructs data type. More... | |
template<typename T > | |
void | deleteClass (VPtr< T, Derived > &p) |
Destructs data type and frees memory. More... | |
template<typename T > | |
VPtr< T, Derived > | newArray (VPtrSize elements) |
Allocates and constructs an array of objects. More... | |
template<typename T > | |
void | deleteArray (VPtr< T, Derived > &p) |
Destructs and frees an array of objects. More... | |
Public Member Functions inherited from virtmem::BaseVAlloc | |
void | start (void) |
Starts the allocator. More... | |
void | stop (void) |
Deinitializes the allocator. More... | |
void | setPoolSize (VPtrSize ps) |
Sets the total size of the memory pool. More... | |
VPtrNum | allocRaw (VPtrSize size) |
Allocates a piece of raw (virtual) memory. More... | |
void | freeRaw (VPtrNum ptr) |
Frees a memory block for re-usage. More... | |
void * | read (VPtrNum p, VPtrSize size) |
Reads a raw block of (virtual) memory. More... | |
void | write (VPtrNum p, const void *d, VPtrSize size) |
Writes a piece of raw data to (virtual) memory. More... | |
void | flush (void) |
Synchronizes all big memory pages. More... | |
void | clearPages (void) |
Synchronizes and clears all big memory pages. More... | |
uint8_t | getFreeBigPages (void) const |
uint8_t | getUnlockedSmallPages (void) const |
Returns amount of small pages which are not locked. | |
uint8_t | getUnlockedMediumPages (void) const |
Returns amount of medium pages which are not locked. | |
uint8_t | getUnlockedBigPages (void) const |
Returns amount of big pages which are not locked. | |
uint8_t | getSmallPageCount (void) const |
Returns total amount of small pages. | |
uint8_t | getMediumPageCount (void) const |
Returns total amount of medium pages. | |
uint8_t | getBigPageCount (void) const |
Returns total amount of big pages. | |
VirtPageSize | getSmallPageSize (void) const |
Returns the size of a small page. | |
VirtPageSize | getMediumPageSize (void) const |
Returns the size of a medium page. | |
VirtPageSize | getBigPageSize (void) const |
Returns the size of a big page. | |
VPtrSize | getPoolSize (void) const |
Returns the size the memory pool. More... | |
VPtrSize | getMemUsed (void) const |
Returns total memory used. | |
VPtrSize | getMaxMemUsed (void) const |
Returns the maximum memory used so far. | |
uint32_t | getBigPageReads (void) const |
Returns the times big pages were read (swapped). | |
uint32_t | getBigPageWrites (void) const |
Returns the times big pages written (synchronized). | |
uint32_t | getBytesRead (void) const |
Returns the amount of bytes read as a result of page swaps. | |
uint32_t | getBytesWritten (void) const |
Returns the amount of bytes written as a results of page swaps. | |
void | resetStats (void) |
Reset all statistics. Called by start() | |
Static Public Member Functions | |
static VAlloc * | getInstance (void) |
Returns a pointer to the instance of the class. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from virtmem::BaseVAlloc | |
void | writeZeros (VPtrNum start, VPtrSize n) |
Writes zeros to raw virtual memory. Can be used to initialize the memory pool. More... | |
virtual void | doStart (void)=0 |
virtual void | doStop (void)=0 |
virtual void | doRead (void *data, VPtrSize offset, VPtrSize size)=0 |
virtual void | doWrite (const void *data, VPtrSize offset, VPtrSize size)=0 |
Base template class for virtual memory allocators.
This template class is used as parent class for all allocators. Most of the actual code is defined in BaseVAlloc, while this class only contains code dependent upon template parameters (i.e. page settings).
Properties | Allocator properties, see DefaultAllocProperties |
Derived | Dummy parameter, used to create unique singleton instances for each derived class. |
using virtmem::VAlloc< Properties, Derived >::VPtr = virtmem::VPtr<T, Derived> |
Similar to TVPtr, but slightly shorter syntax (C++11 only) Example:
T | Type of virtual pointer |
|
inline |
Allocates memory from the linked virtual memory allocator.
T | The data type to allocate for. |
size | The number of bytes to allocate. By default this is the size of the type pointed to. |
This function is the equivelant of the C malloc
function. To allocate memory for an array multiply the array size by the size of the type, for instance:
|
inline |
Destructs and frees an array of objects.
p | Virtual pointer to array that should be deleted |
This function is similar to the C++ delete []
operator. After calling all the destructors of each object, the respective memory block will be freed.
|
inline |
Destructs data type and frees memory.
p | virtual pointer to delete |
This function is similar to the C++ delete
operator. After calling the destructor of the data type the respective memory block will be freed.
|
inline |
Frees a block of virtual memory.
p | virtual pointer that points to block to be freed |
This function is the equivelant of the C free
function. The pointer will be set to null.
|
inlinestatic |
Returns a pointer to the instance of the class.
All allocator classes are singletons: only one instance can exist for a particular allocator.
Note that, since allocators are template classes, one instance is generated for every set of unique template parameters. For example:
In this case, alloc1
and alloc2
are variables with a different type, hence getInstance() will return a different instance for both classes.
|
inline |
Allocates and constructs an array of objects.
elements | the size of the array |
This function is similar to the C++ new [] operator. After allocating sufficient size for the array, the default constructor will be called for each object.
|
inline |
Allocates memory and constructs data type.
T | The data type to allocate for. |
size | The number of bytes to allocate. By default this is the size of the type pointed to. |
This function is similar to the C++ new
operator. Similar to alloc, this function will allocate a block of virtual memory. Subsequently, the default constructor of the data type is called. For this reason, this function is typically used for C++ classes.