Tencent / rapidjson

A fast JSON parser/generator for C++ with both SAX/DOM style API
http://rapidjson.org/
Other
14.27k stars 3.53k forks source link

Copy json string into malloc'd buffer #1492

Open michaeleisel opened 5 years ago

michaeleisel commented 5 years ago

When I make parsers on top of the RapidJSON SAX parser to convert json into objects of a certain language, I find that I always need to copy the RapidJSON string into my own allocated buffer that I can pass to the language's native string constructor for it to own and later free. What I would prefer is for RapidJSON to copy directly into an allocated buffer, either one that I allocate or one that it allocates. This is more efficient and is nondestructive. Thoughts?

miloyip commented 5 years ago

How about using kParseInsituFlag?

michaeleisel commented 5 years ago

that provides a nice performance boost, and it is my current preferred way, but it is destructive and potentially less performant than this. however, the length would need to be figured out before the malloc, i wonder if that will cause the speedup not to be that great.