Ethan Holman's Website & Blog
The Arduino Uno and most other models only have 2KB of RAM. Since it's very easy to fill this up, I created this simple pagefile/swap code, which utilizes an SD card attached to the arduino. Basically, it will make a directory on the SD card and save variables as text files. Variable name = text file name, variable contents = text file contents. Very simple! While possibly not the most efficient system, it has been doing the job well.

This code depends on the arduino SD library, so make sure to add this:

#include 
File myFile;
Getting contents of variable:
swap("variable_name");
And creating / setting value of variable:
swap("variable_name", "value");
The complete code:

#include 
File myFile;

void setup() {
  Serial.begin(9600);
  initSwap();
}

void loop() {
  
}

void initSwap() {
  pinMode(10, OUTPUT);
  SD.begin(4);
}

String swap(String varName) {
  String value = "";
  
  String tempPath = ("swap/" + varName + ".txt");
  char filename[tempPath.length()+1];
  tempPath.toCharArray(filename, sizeof(filename));
  
  if(SD.exists(filename)) {
    myFile = SD.open(filename);
	while(myFile.available()) {
	  value = value + (char)myFile.read();
	}
	myFile.close();
  }
  return value;
}

void swap(String varName, String varVal) {
  String tempPath = ("swap/" + varName + ".txt");
  char filename[tempPath.length()+1];
  tempPath.toCharArray(filename, sizeof(filename));
  
  if(SD.exists(filename)) SD.remove(filename);
  myFile = SD.open(filename, FILE_WRITE);
  if(myFile) {
    myFile.print(varVal);
	myFile.close();
  }
}