Sorry for my double reply, and thank you very much for your help! I think there is still anything strange going on, Iet me explain more detailed:
The following code
#include <Arduino.h>
#include <Esp.h>
int* var1 = (int*) calloc(24000, sizeof(int));
void setup() {
Serial.begin(115200);
for(int i = 0; i < 24000; i++){
var1[i] = i;
}
Serial.printf("biggest free block: %i\n", heap_caps_get_largest_free_block(MALLOC_CAP_8BIT));
}
void loop() {
Serial.println("main");
delay(2000);
}
fails, and results in a rebooting loop (not even entering setup() ). And of course this could be explained (as you said) by the fact, that the ram is split up in some blocks (3 blocks with ~114000 bytes?). Running an empty script, the largest available block reported is in my case 113792 bytes. Although var1 has a total size of "only" 96000 bytes, I could imagine that some memory of the block is used while booting, and released before entering setup() ... So, this could be ok.
So, coming to something I cannot understand:
The following code
#include <Arduino.h>
#include <Esp.h>
int * var1 = (int*) calloc (23000, sizeof(int));
void setup() {
Serial.begin(115200);
var1[0] = 1;
Serial.printf("biggest free block: %i\n", heap_caps_get_largest_free_block(MALLOC_CAP_8BIT));
}
void loop() {
Serial.println("main");
delay(2000);
}
works fine, and in setup() the chip reports still a largest free block size of 113792. So in principle it should be possible to allocate another memory block like the one for var1 right? But this fail and results in an reboot loop. Also trying to allocate a smaller block for e.g. only 2000 integer values fails, although there should be a free memory block of more than 100kKByte. This is strange, I do not understand why this happens.
So, declaring global Variables with a total size bigger than ~94 KByte fail. I have tried with multiple chips, and flashing the chips with Arduino IDE, as well as PlatformIO. I also tried to allocate the memory in smaller blocks, nothing worked. As soon as the total allocated GLOBAL memory gets bigger than ~9400 KByte, the chips end up in a reboot loop.
What DOES work, is declaring the variables in a local scope:
#include <Arduino.h>
#include <Esp.h>
void setup() {
Serial.begin(115200);
//filling the memory with some values...
int* var1 = (int*) calloc(23000, sizeof(int));
int* var2 = (int*) calloc(23000, sizeof(int));
for(int i = 0; i < 23000; i++){
var1[i] = i;
var2[i] = i;
}
delay(500);
Serial.printf("biggest free block: %i\n", heap_caps_get_largest_free_block(MALLOC_CAP_8BIT));
}
void loop() {
Serial.println("main");
delay(2000);
}
removing var2, the chips still reports a largest block of 113792, and i can allocate (in this case) the full empty block (I tried allocating 112 KByte, and it worked). So this is working as expected. A bit strange, (but still explainable) is, that var1 still must not be bigger than ~94 KByte. I think this could be due to memory needed while booting.
In summary, it looks like one can only allocate memory of one of the 3 ram block in global scope... Is there any suitable reason for this, or is this a bug? I know, there are simple workarounds, but if one can allocate global memory, why only a part of it?
Best, Christoph