bblanchon / ArduinoJson

📟 JSON library for Arduino and embedded C++. Simple and efficient.
https://arduinojson.org
MIT License
6.74k stars 1.12k forks source link

When is the peak value reached? #2132

Closed butaikis closed 1 month ago

butaikis commented 1 month ago

Hi. I sometimes use an assistant for approximate calculation of the JSON buffer and there is a question. There is RAM Usage on the page, there is the main value and just below it is Peak. In which cases is the Peak value reached?

bblanchon commented 1 month ago

Hi @butaikis,

Memory consumption increases temporarily during deserialization; that's when the peak is reached.

In other words, the "regular" RAM usage corresponds to the final JsonDocument, whereas the peak accounts for the temporary overhead of deserializeJson().

Best regards, Benoit

butaikis commented 1 month ago

@bblanchon Understood, thanks for the explanation. Please tell me if I use the reading from LittleFS function.

  DynamicJsonDocument BUFFER_JSON(61440);
  File FRead= FS_User.open("/test.json", "r");
  DeserializationError error = deserializeJson(BUFFER_JSON, FRead);
  FRead.close();

Is it more correct to choose Input: Stream in the assistant?

bblanchon commented 1 month ago

LittleFS's File implements the Stream interface; that's why you can pass it directly to deserializeJson(). In the Assistant, you should, therefore, choose "Stream" for the input type.

By the way, in ArduinoJson 7, you can simply declare your document as JsonDocument BUFFER_JSON;.

butaikis commented 1 month ago

@bblanchon Thanks!

bblanchon commented 1 month ago

You're welcome, @butaikis. Thank you for using ArduinoJson! Don't forget to cast a star to support the project :wink: