virtmem
virtual memory library for Arduino
|
Base class for virtual memory allocators. More...
#include <base_alloc.h>
Public Member Functions | |
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... | |
Statistics functions. | |
The following functions are only available when VIRTMEM_TRACE_STATS is defined (in config.h). | |
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() | |
Protected Member Functions | |
void | writeZeros (VPtrNum start, VPtrSize n) |
Writes zeros to raw virtual memory. Can be used to initialize the memory pool. More... | |
Pure virtual functions | |
The following functions should be defined by derived allocator classes. | |
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 class for virtual memory allocators.
This class defines methods to (de)initialize the allocator (see start() and stop()). In addition, this class can be used for 'raw' memory access.
Allocates a piece of raw (virtual) memory.
size | the size of the memory block |
void virtmem::BaseVAlloc::clearPages | ( | void | ) |
Synchronizes and clears all big memory pages.
void virtmem::BaseVAlloc::flush | ( | void | ) |
Synchronizes all big memory pages.
void virtmem::BaseVAlloc::freeRaw | ( | VPtrNum | ptr | ) |
Frees a memory block for re-usage.
ptr | starting address of the memory block. This function will do nothing if ptr is zero. |
uint8_t virtmem::BaseVAlloc::getFreeBigPages | ( | void | ) | const |
|
inline |
Returns the size the memory pool.
Reads a raw block of (virtual) memory.
p | starting address of memory block |
size | number of bytes to read |
|
inline |
Sets the total size of the memory pool.
ps | size of the memory pool. |
void virtmem::BaseVAlloc::start | ( | void | ) |
Starts the allocator.
This function should always be called during initialization, i.e. in setup() function of your sketch. If the allocator was stopped (see stop()), this function should be called again before using the allocator. All used virtual memory (if any) will be cleared during initialization.
void virtmem::BaseVAlloc::stop | ( | void | ) |
Deinitializes the allocator.
Run start() before using the allocator to re-initialize it.
Writes a piece of raw data to (virtual) memory.
p | starting address of the virtual memory block |
d | pointer to data to be written |
size | number of bytes to write |
Writes zeros to raw virtual memory. Can be used to initialize the memory pool.
start | Start address |
n | Amount of bytes (zeros) to write |