virtmem
virtual memory library for Arduino
virtmem::BaseVAlloc Class Referenceabstract

Base class for virtual memory allocators. More...

#include <base_alloc.h>

Inheritance diagram for virtmem::BaseVAlloc:
virtmem::VAlloc< Properties, MultiSPIRAMVAllocP< SPIChips, chipAmount, Properties > > virtmem::VAlloc< Properties, SDVAllocP< Properties > > virtmem::VAlloc< Properties, SerialVAllocP< IOStream, Properties > > virtmem::VAlloc< Properties, SPIRAMVAllocP< Properties > > virtmem::VAlloc< Properties, StaticVAllocP< poolSize, Properties > > virtmem::VAlloc< Properties, StdioVAllocP< Properties > > virtmem::VAlloc< Properties, Derived > virtmem::MultiSPIRAMVAllocP< SPIChips, chipAmount, Properties > virtmem::SDVAllocP< Properties > virtmem::SerialVAllocP< IOStream, Properties > virtmem::SPIRAMVAllocP< Properties > virtmem::StaticVAllocP< poolSize, Properties > virtmem::StdioVAllocP< Properties >

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
 

Detailed Description

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.

Member Function Documentation

VPtrNum virtmem::BaseVAlloc::allocRaw ( VPtrSize  size)

Allocates a piece of raw (virtual) memory.

Parameters
sizethe size of the memory block
Returns
The starting address of the memory block. Will return zero if out of memory.
void virtmem::BaseVAlloc::clearPages ( void  )

Synchronizes and clears all big memory pages.

Note
This function is merely used for debugging.
void virtmem::BaseVAlloc::flush ( void  )

Synchronizes all big memory pages.

Note
This function is merely used for debugging.
void virtmem::BaseVAlloc::freeRaw ( VPtrNum  ptr)

Frees a memory block for re-usage.

Parameters
ptrstarting address of the memory block. This function will do nothing if ptr is zero.
uint8_t virtmem::BaseVAlloc::getFreeBigPages ( void  ) const
Returns
number of big pages that are not used and are not locked.
VPtrSize virtmem::BaseVAlloc::getPoolSize ( void  ) const
inline

Returns the size the memory pool.

Note
Some memory is used for bookkeeping, therefore, the amount returned by this function does not equate the amount that can be allocated.
void * virtmem::BaseVAlloc::read ( VPtrNum  p,
VPtrSize  size 
)

Reads a raw block of (virtual) memory.

Parameters
pstarting address of memory block
sizenumber of bytes to read
Returns
a pointer to a memory block (a memory page) containing the data
Note
The memory block returned by this function is temporary and may be invalidated during a page swap. To use the memory accross reads and writes it should be locked.
void virtmem::BaseVAlloc::setPoolSize ( VPtrSize  ps)
inline

Sets the total size of the memory pool.

Parameters
pssize of the memory pool.
Note
The poolsize can also be set via the constructor of most allocators.
This function is unavailable for MultiSPIRAMVAllocP and StaticVAlloc.
This function should always called before start().
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.

Examples:
multispiram_simple.ino.
void virtmem::BaseVAlloc::stop ( void  )

Deinitializes the allocator.

Run start() before using the allocator to re-initialize it.

void virtmem::BaseVAlloc::write ( VPtrNum  p,
const void *  d,
VPtrSize  size 
)

Writes a piece of raw data to (virtual) memory.

Parameters
pstarting address of the virtual memory block
dpointer to data to be written
sizenumber of bytes to write
void virtmem::BaseVAlloc::writeZeros ( VPtrNum  start,
VPtrSize  n 
)
protected

Writes zeros to raw virtual memory. Can be used to initialize the memory pool.

Parameters
startStart address
nAmount of bytes (zeros) to write

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