Efficient use of big byte arrays?

Hello everybody.

I'm rewriting a library in which I want to use 5 large arrays. The arrays each consist of ~1000 to ~7500 uint8_t values. So total ~12k Ram.

The bits of the bytes represent image information (5 different fonts).

At the same time I always use "one" of the arrays / fonts. Although I have enough memory available, would still like to know how to use such arrays most efficient?

  • Can I load arrays only when needed or do they need to be present in memory all the time?
  • How to best define such arrays (different include's? all in one include file?)

I have also read something from the keyword "external".

So total ~12k Ram

Which Arduino do you plan to use?

For the current project…an ESP32 is used. For this I have to rewrite an OLED library.

You could store all the arrays in SPIFFS and only read in the one you need at run-time.

SPIFFS? Nice idea! I can use that elsewhere to outsource system files from the sd card. I would like to write the library "arduino compatible" to use this on non-ESP if necessary. is there still another possibility?

Read only arrays can go in flash, ie PROGMEM on ATmega's

Thanks, but I think the flash will not be big enough.

I would like to save the arrays in the ram now. However, I have problems with the definition of the arrays. Since I need additional information (height / width), I have planned to use a struct.

However, I do not understand why the compiler has a problem.

Font.h:

#ifndef Font_h
#define Font_h

struct sFont{
	uint8_t* table;
	uint8_t width;
	uint8_t height;
};
sFont Font8 = { Font8_Table,5,8 };
#endif

Font8.cpp:

#ifndef Font8_cpp
#define Font8_cpp

#include "Font.h"

extern const uint8_t Font8_Table[] = {0x00,0x00,0x00}//example

#endif

if I include the font.h, I get the message:
sketch\font\Font.h:10:3: error: 'Font8_Table' was not declared in this scope

Just about everything there is wrong. Try:

Font.h:

#ifndef Font_h
#define Font_h
#include <Arduino.h>
struct sFont{
  const uint8_t * table;
  uint8_t width;
  uint8_t height;
};

extern sFont Font8;
#endif

Font.cpp:

#include "Font.h"

static const uint8_t Font8_Table[] = {0x00,0x01,0x02}; //example
sFont Font8 = { Font8_Table,5,8 };

Accessing the struct from main.ino:

#include "Font.h"
void setup() {
  Serial.begin(115200);
  delay(1000);  
  Serial.println(Font8.table[0]);
  Serial.println(Font8.table[1]);
  Serial.println(Font8.table[2]);
  Serial.println(Font8.width);
  Serial.println(Font8.height);
}

void loop() {
}

First of all...thanks.

I had built up comparable. but I always got the message that Font8 is an undefined reference.

The reason: I had the .h and .cpp file in the subfolder "Font".
Included with...

#include "Font/Font.h"

If I put the files directly into the sketch folder, I can use them as planned.
Included with...
[code]#include "Font.h"[/code]

Do you know the reason?

You can put the .h file in a sub folder and #include it with a relative path name. But, the .cpp files need to go in the main folder with the .ino file.

Does c handle the behaviors differently than cpp?

I have seen in the original library that there are the "c" files also in subdirectories.
declaration, struct,... are marked as C:

extern "C" {...}