virtmem: easily extend your memory

Status
Not open for further replies.

-Rick-

New member
Hello all,

virtmem is an Arduino (and Teensyduino!) library that makes it easy to extend the limited RAM available on microcontrollers with 'virtual memory'. To do so, virtmem provides a simple interface to use external memory sources such as an SD card or SPI RAM chip which resembles working with 'regular' memory.

Some of its main features are:
  • Extend the available memory with kilobytes, megabytes or even gigabytes
  • Supports SPI RAM (23LC series from Microchip), SD cards and RAM from a computer connected through serial
  • Easy C++ interface that closely resembles regular data access
  • Memory page system to speed up access to virtual memory
  • New memory interfaces can be added easily

And a small demonstration that uses an SD card as memory source:
Code:
#include <Arduino.h>
#include <SdFat.h>
#include <virtmem.h>
#include <alloc/sd_alloc.h>

// Simplify virtmem usage
using namespace virtmem;

// Create virtual a memory allocator that uses SD card (with FAT filesystem) as virtual memory pool
// The default memory pool size (1 MB) is used.
SDVAlloc valloc;

SdFat sd;

struct MyStruct { int x, y; };

void setup()
{
    // Initialize SdFatlib
    if (!sd.begin(9, SPI_FULL_SPEED))
        sd.initErrorHalt();

    valloc.start(); // Always call this to initialize the allocator before using it

    // Allocate a char buffer of 10000 bytes in virtual memory and store the address to a virtual pointer
    VPtr<char, SDVAlloc> str = valloc.alloc<char>(10000);

    // Set the first 1000 bytes to 'A'
    memset(str, 'A', 1000);

    // array access
    str[1] = 'B';

    // Own types (structs/classes) also work.
    VPtr<MyStruct, SDVAlloc> ms = valloc.alloc<MyStruct>(); // alloc call without parameters: use automatic size deduction
    ms->x = 5;
    ms->y = 15;
}

void loop()
{
    // ...
}

The project is hosted on github: https://github.com/rhelmus/virtmem
A detailed manual with more info can be found here: http://rhelmus.github.io/virtmem/index.html

Most of the development was done on Teensy 3.X boards. This is the first release, but already pretty feature complete. Nevertheless, any feedback (questions, suggestions, bugs etc) is welcome!
 
Hmmm, I wonder if this would be useful with OTA? Have you tried loading the binary of a sketch into this virtual memory, or am I totally off base here?
 
Huh. Very cool. Will have a play.
One particular application springs to mind because I know it's something some of the guys here struggle with a tidy solution for; audio delays.

Thanks for sharing!
 
Yeah, I'm aware of that solution. Just wondered whether this could potentially provide an alternate solution for those interested in it. (Not something I need personally).
 
Thanks for the feedback!

Hmmm, I wonder if this would be useful with OTA? Have you tried loading the binary of a sketch into this virtual memory, or am I totally off base here?
I am not so familiar with this topic. I think the binary instructions could be put in virtual memory. You would still need to find a way to properly execute the chunks.

Cosford said:
Huh. Very cool. Will have a play.
One particular application springs to mind because I know it's something some of the guys here struggle with a tidy solution for; audio delays.

Thanks for sharing!
Yes, I guess virtmem could bring a nice alternative to that. What kind of speed requirements are we talking about?
 
Status
Not open for further replies.
Back
Top