2

I am running out of memory on my Arduino due to the libraries I am using. After I have included all the libraries I need then there is very little in the way of free memory for my own code.

If hook up some external RAM to the Arduino, is there a way I can make existing libraries use the external RAM rather than the SRAM on the arduino or will I need to alter the code in the library to do it.

If I have to modify the code is that a relatively easy thing to do?

  • Hello and welcome. I would think that this is very specific to the libraries involved (could you specify them?) - albeit somewhat unlikely in a generic sense. – Ghanima Apr 29 '17 at 17:52
  • Thanks for the welcome :-) The ones I am thinking of at the moment are the Adafruit OLED library here and the SD card library here – SpeedOfSpin Apr 29 '17 at 18:22
2

What did programmers do back in the 80-ies when they run out of memory?

There is an old technique called overlays. The same area of memory is used for different phases/steps of a program. Results are naturally saved but any intermediate data is discharged before the next phase/step which reuses the "common" area of memory. Necessary state may be saved to an external storage between execution of the phase/step to increase available local memory.

To compile and link this you have to do some deep diving into the manual and read up on memory sections.

It is possible to abstract this using C++ smart pointers but getting existing libraries to use it will be a very tough challenge. There are a few attempts to support virtual memory such as virtmem.

Cheers!

  • Thanks. I have seen the virtmem library before in passing but took a close look and it looks like it might get me part of the way there. – SpeedOfSpin Apr 29 '17 at 20:13
  • Before considering using overlay, virtual memory and external memory (e.g. SPI RAM) use all the available tricks to reduce SRAM usage such as the F() macro, limit the usage of String class, reducing allocation size, packing struct's, etc. – Mikael Patel Apr 30 '17 at 10:57
3

Making a library use external SRAM is not an easy task. It can be cone, but it takes quite a bit of work.

The best start would be to abstract the SRAM into a library that provides simple access to it. Then you would need to use that new library to read and write data in the SRAM instead of accessing variables in the other libraries.

There is no way of simply mapping a variable into external SRAM - for that you need a microcontroller with an MMU and/or an EIB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.