Changing size of array by ready array from EEPROM?

Hey,
I would like to store a few byte Arrays in EEPROM, each in different size.
i.e
byte ar1[5] = {1,2,3,4,5};
byte ar2[6] = {1,2,3,4,5,6};
byte ar3[7] = {1,2,3,4,5,4,9};

and on my sketch I would like to use one of thous arrays and change it from time to time by loading it from EEPORM

i.e.
byte generalArray[0];

clear the generalArray and load ar1 into generalArray.

later on, clear generalArray again and load ar3 into generalArray

I don't have any idea on how to do that...

Can you give me a simple example?

byte generalArray[0];How many elements are in this array ?

To do what you want you need to declare the array in the program with the maximum number of elements that may be used later.

Then you can read bytes from EEPROM and put them in the array. You will need to know where the array data starts in EEPROM and how many elements are to be read. Maybe start each set of array data every 10 bytes for arrays of 9 bytes max and end the array data with a marker such as 0xFF if that data does not occur in the array. Alternative make the first thing read from the EEPROM the number of elements in the array.

I would suggest that you look at the EEPROM examples in the IDE.

Acctually, with "unknow" sizes I find much easier to use EEMEM.

Here is a sample of what you want...
I made it in functions, so you don't need to throw RAM away using the maximum possible size for the tempArray, but if you need it to be a global variable then you should consider the maximum possible size that it can assume.

byte E_ARRAY1[3] EEMEM;
byte E_ARRAY2[4] EEMEM;
byte E_ARRAY3[5] EEMEM;


void setup() {
  byte array1[] = {1, 2, 3}; // REMOVE AFTER THE FIRST EXECUTION
  byte array2[] = {4, 5, 6, 7}; // REMOVE AFTER THE FIRST EXECUTION
  byte array3[] = {8, 9, 10, 11, 12}; // REMOVE AFTER THE FIRST EXECUTION
  eeprom_write_block(&array1, &E_ARRAY1, sizeof(E_ARRAY1)); // REMOVE AFTER THE FIRST EXECUTION
  eeprom_write_block(&array2, &E_ARRAY2, sizeof(E_ARRAY2)); // REMOVE AFTER THE FIRST EXECUTION
  eeprom_write_block(&array3, &E_ARRAY3, sizeof(E_ARRAY3)); // REMOVE AFTER THE FIRST EXECUTION
  Serial.begin(9600);
  printArray1();
  printArray2();
  printArray3();
}

void loop() {
  // put your main code here, to run repeatedly:

}

void printArray1() {
  byte tempArray[sizeof(E_ARRAY1)] = {};
  eeprom_read_block(&tempArray, &E_ARRAY1, sizeof(E_ARRAY1));
  Serial.print("array1 = ");
  for (byte i = 0; i < sizeof(tempArray); i++) {
    Serial.print(tempArray[i]);
    Serial.print(", ");
  }
  Serial.println();
}

void printArray2() {
  byte tempArray[sizeof(E_ARRAY2)] = {};
  eeprom_read_block(&tempArray, &E_ARRAY2, sizeof(E_ARRAY2));
  Serial.print("array2 = ");
  for (byte i = 0; i < sizeof(tempArray); i++) {
    Serial.print(tempArray[i]);
    Serial.print(", ");
  }
  Serial.println();
}

void printArray3() {
  byte tempArray[sizeof(E_ARRAY3)] = {};
  eeprom_read_block(&tempArray, &E_ARRAY3, sizeof(E_ARRAY3));
  Serial.print("array3 = ");
  for (byte i = 0; i < sizeof(tempArray); i++) {
    Serial.print(tempArray[i]);
    Serial.print(", ");
  }
  Serial.println();
}