Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: virtmem: easily extend your memory

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    3

    virtmem: easily extend your memory

    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!

  2. #2
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    909
    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?

  3. #3
    Senior Member
    Join Date
    Dec 2014
    Posts
    299
    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!

  4. #4
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,878
    Quote Originally Posted by Cosford View Post
    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.
    For audio delays, you may consider also Frank's Memoryboard. See also Paul's 9s delay demo, e.g.
    https://forum.pjrc.com/threads/29276...ll=1#post80049

  5. #5
    Senior Member
    Join Date
    Dec 2014
    Posts
    299
    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).

  6. #6
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks for the feedback!

    Quote Originally Posted by duff View Post
    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.

    Quote Originally Posted by Cosford
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •