ArduinoJson
ArduinoJson copied to clipboard
How is memory allocated?
Hi @bblanchon. I have ESP32-WROVER-IE (FLASH 8MB, PSRAM 8MB). I tested different amounts of memory allocation for JSON
DynamicJsonDocument testjs{7000000};
or
DynamicJsonDocument testjs{70000000};
In all cases, the test js.capacity() function returned the correct number of bytes. But I don't understand how, because I don't have that much RAM.
Code:
OUTPUT_JSON["buf_testjs"] = testjs.capacity();
OUTPUT_JSON["psram_size_all"] = esp_spiram_get_size();
OUTPUT_JSON["psram_size"] = ESP.getPsramSize();
OUTPUT_JSON["psram_free"] = ESP.getFreePsram();
OUTPUT_JSON["free_heap"] = ESP.getFreeHeap();
OUTPUT_JSON["free_heap2"] = heap_caps_get_free_size(MALLOC_CAP_8BIT);
OUTPUT_JSON["psram_himem_size"] = esp_himem_get_phys_size();
Result:
"buf_testjs": 70000000,
"psram_size_all": 8388608,
"psram_size": 3913347,
"psram_free": 3791467,
"free_heap": 55187,
"free_heap2": 3809434,
"psram_himem_size": 4456448