Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to pre-allocate memory? v7 #2160

Open
gavinunderdown opened this issue Feb 19, 2025 · 1 comment
Open

Is there a way to pre-allocate memory? v7 #2160

gavinunderdown opened this issue Feb 19, 2025 · 1 comment
Labels
question v7 ArduinoJson 7

Comments

@gavinunderdown
Copy link

With library version 7, is there a way to pre-allocate memory?

I have a large amount of data (80kb raw size in memory) that I want to serialize to an array
"CaptureDataParams": [ [ 305, -2756, 3074.97998, 2130792586, 2130792586, 2047 ], [ 306, -2786, 3075.919922, 2130792278, 2130792278, 2047 ], [ 307, -2816, 3076.530029, 2130791970, 2130791970, 2047 ], ...

I have 5000 of these items, and at least in memory they are a fixed size.

Is there a way to pre-allocate the memory for the nested arrays, such that for each iteration I only have to end up calling malloc() 2-3 times?

@bblanchon
Copy link
Owner

Hi @gavinunderdown,

With library version 7, is there a way to pre-allocate memory?

No, ArduinoJson 7 doesn't let you preallocate the memory for the array.

I have 5000 of these items, and at least in memory they are a fixed size.

JSON isn't a good fit for your data; you should use a good ol' binary format.

Best regards,
Benoit

@bblanchon bblanchon added the v7 ArduinoJson 7 label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question v7 ArduinoJson 7
Projects
None yet
Development

No branches or pull requests

2 participants