profile
viewpoint

Ask questionsShould a document be reused in repeated parsing?

Hi, I have a callback function in a class looks like below,

void myclass::on_message(const string& msg) {
    Document doc;
    doc.Parse(msg);
}

or should I declare doc as a member of myclass and use as

class myclass {
...
Document doc;
}

void myclass::on_message(const string& msg) {
    doc.Parse(msg);
}

I was wondering if the first method will be less performant because each callback will construct a Document object? or I can actually dont care because construction of Document object is pretty fast? what is the best way to handle such scenario?

If I go for second, I fould this thread https://github.com/Tencent/rapidjson/issues/1605, mentioned,

d.SetNull();
d.GetAllocator().Clear();

I wonder which way is better?

Tencent/rapidjson

Answer questions miloyip

Using Document as local variable is the easiest way to go, if it is sufficient for your use case. Just parse, retrieve information and convert the information to your internal representation.

useful!

Related questions

是否支持流式解析以及多个json分离解析 hot 1
是否支持流式解析以及多个json分离解析 hot 1
RapidJSON causes cc1plus: internal compiler error: Segmentation fault - rapidjson hot 1
GenericMemberIterator::Iterator implicitly declared private when RAPIDJSON_NOMEMBERITERATORCLASS is defined hot 1
Always gets a core dump while creating json string (rapidjson) hot 1
Bazel Support hot 1
Syntax typo in tutorial hot 1
是否支持流式解析以及多个json分离解析 hot 1
作者你好,我 想请教一下,这个框架是否能够将变量中文stirng 转成wchar_t? 在文档只看到定量 hot 1
travis on windows hot 1
Added headers to my project and got thousands of errors hot 1
Added headers to my project and got thousands of errors hot 1
想要的反斜杠 \. 无法表示,否则JSON解析出错 hot 1
Assertion `stack_.GetSize() == sizeof(ValueType)' failed hot 1
source:https://uonfu.com/
Github User Rank List