-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
How to reuse the parser and serializer intermediate storage? #1847
Comments
What do you mean? |
Lets rewind. Does this library allocate temporary storage when parsing a JSON? |
Do you expect parsing the json in-place? |
No, I'm looking at the use-case of parsing a JSON into an |
The lexer (https://github.com/nlohmann/json/blob/develop/include/nlohmann/detail/input/lexer.hpp#L1481) and the parser (https://github.com/nlohmann/json/blob/develop/include/nlohmann/detail/input/parser.hpp#L487) manage their state in some member variables. It is not the state of the parsing (i.e., the stack needed to process the input), but rather the glue between input, lexer, and parser, as well as some variables to hold parsed values, error codes, etc. The actual hierarchy is managed in the SAX parser implementations (https://github.com/nlohmann/json/blob/develop/include/nlohmann/detail/input/json_sax.hpp#L317). None of this can currently be reused. |
That was very helpful thanks. The one-off variables are not interesting but these are:
and
These could be reused if the caller desires to parse several JSON texts in a row. |
Could be. Any idea how to achieve this with a nice API? |
Hard to say, I would have to study the library in-depth to figure out how to do it harmoniously. You could just pack them up into a class and require the caller pass the address of it as the last parameter, or if the parameter is left out than a temporary one is used. |
If I am parsing or serializing multiple JSON in a row, is there a way to re-use the intermediate storage used for those operations in between values?
The text was updated successfully, but these errors were encountered: