Rapidjson: document如何释放已有数据

Created on 18 Oct 2017  ·  3Comments  ·  Source: Tencent/rapidjson

  1. 使用document解析完了一个文件,在解析新文件之前如何释放document所有数据?
  2. 如何判断当前document中有数据?
question

Most helpful comment

  1. 至少两个方法

(a) 可用 STL 常用的方式:

~cpp
Document doc;
// ...
{
Document newDoc;
doc.Swap(newDoc);
}
~

(b) 用预设的 allocator 类型的话,又保证分配了的内存不再被使用,可:

~cpp
doc.SetNull(); // 把根节点设为 null JSON 类型
doc.GetAllocator().Clear(); // 清空 allocator
~

  1. 用预设的 allocator 类型的话,可用 doc.GetAllocator().Size() 返回已分配的大小.

All 3 comments

  1. 至少两个方法

(a) 可用 STL 常用的方式:

~cpp
Document doc;
// ...
{
Document newDoc;
doc.Swap(newDoc);
}
~

(b) 用预设的 allocator 类型的话,又保证分配了的内存不再被使用,可:

~cpp
doc.SetNull(); // 把根节点设为 null JSON 类型
doc.GetAllocator().Clear(); // 清空 allocator
~

  1. 用预设的 allocator 类型的话,可用 doc.GetAllocator().Size() 返回已分配的大小.

非常感谢~~~

在 2017-10-20 10:52:20,"Milo Yip" notifications@github.com 写道:

至少两个方法

(a) 可用 STL 常用的方式:

Document doc;
// ...
{
Document newDoc;
doc.Swap(newDoc);
}

(b) 用预设的 allocator 类型的话,又保证分配了的内存不再被使用,可:

doc.SetNull(); // 把根节点设为 null JSON 类型
doc.GetAllocator().Clear(); // 清空 allocator
用预设的 allocator 类型的话,可用 doc.GetAllocator().Size() 返回已分配的大小.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

非常感谢~~~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lixiaofan0 picture lixiaofan0  ·  3Comments

europelee picture europelee  ·  5Comments

dan-ryan picture dan-ryan  ·  6Comments

hhzrz picture hhzrz  ·  3Comments

vzaluckis picture vzaluckis  ·  4Comments