Comments (4)
Hi @mathieucarbou,
I must be honest with you: I don't understand anything about this use case, and from where I stand, it looks like a very convoluted solution to a rather simple problem.
If you believe that an allocator would solve your problem, why don't you replace JsonDocument
's allocator?
ArduinoJson already allows you to replace the allocator; you don't need me to do that.
Best regards,
Benoit
from arduinojson.
ESP-DASH (https://github.com/ayushsharma82/ESP-DASH) is a web framework working on top of websocket.
It communicates through websocket evens to send the updates and initial layout to the browser.
When the application is huge, ESP-DASH has to build a Json document that can be big (i.e. in my app, the measureJson tell a size more than 12k of data).
There is no way to stream that directly because the underlying wesocket layer works by sending packets, so the Json document has to be serialised in a buffer that will be put in a queue for sending (this is a low level library doing that)
So at this time, the heap needs to contain both the JsonDocument (which can use more than 12k), and the websocket buffer (12k). To fix that and not overflow, each time we append a new UI element to the json websocket message, we use measureJson
to check the payload size and if it reaches a limit, we send it, then clear the json document for the next UI elements.
The problem is that it causes a LOT of measureJson
calls, that could be avoided if we could set a cap in the memory used by a json document.
The data is user-driven, we have no control over the sizes: for example, a first part of the UI could be big in app A and small in app B. it depends on the titles, components, charts, etc.
I have tried to replaced the allocator but bumped into the issue described in #2033. This is not possible to set a limit because some API in the allocator does not allow to keep track of what is really allocated.
from arduinojson.
I'm assuming you are referring to ArduinoJson's Allocator
interface not providing the block size when deallocating or reallocating. You can easily work around this limitation by prefixing each block with its size. I use this technique in the SpyingAllocator
for example.
Alternatively, since your goal is to keep a safety cushion, you could check the amount of free heap before allocating a buffer.
from arduinojson.
Thanks! I didn't think about these ideas. I will try them.
from arduinojson.
Related Issues (20)
- V6 Documentation ArduinoJson PubSubClient with StreamUtils HOT 1
- deserialize file from LittleFS crash HOT 6
- Trying to compile a 2021 program HOT 2
- Bring back zero-copy mode in v7 HOT 6
- MQTT Publish destroying Json HOT 2
- Error compiling example code SimpleParser on Arduino Web Editor NodeMCU 0.9 HOT 1
- JSON output is truncated. HOT 1
- load an object into an absolute memory address, Cortex-M. HOT 4
- Cannot compile code that compiled last time it was used HOT 1
- There is a memory leak either in this library or in ESP32 LittleFS HOT 23
- Lint error ovl_no_viable_subscript has occured HOT 2
- Cleaning HTML Chuking Answer at the Custom Reader class for getting filtered JsonDocument HOT 1
- Return JsonDocument from class methods HOT 2
- Question - Access JSON data variables in nested arrays HOT 5
- Problem whith a JSON from Firefox to my ESP8266 HOT 3
- fatal error: ArduinoJson/Variant/VariantRefBase.hpp: No such file or directory HOT 1
- Example on ArduinoJson website crashes at runtime HOT 1
- ArduinoJson 7.1.0 Compile error [ invalid use of array with unspecified bounds ] HOT 2
- Missing links to specific types in the API reference HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinojson.