Loading…
|
Translation uploaded |
|
|
String added in the repository |
|
Flags
safe-html, strict-same
Loading…
|
Translation uploaded |
|
|
String added in the repository |
|
To achieve performance and memory efficiency, the parser uses a temporary storage area to hold intermediate results. This storage is reused when parsing more than one JSON text, reducing the total number of calls to allocate memory and thus improving performance. Upon construction, the memory resource used to perform allocations for this temporary storage area may be specified. Otherwise, the default memory resource is used. In addition to a memory resource, the parser can make use of a caller-owned buffer for temporary storage. This can help avoid dynamic allocations for small inputs. The following example uses a four kilobyte temporary buffer for the parser, and falls back to the default memory resource if needed:为实现性能与内存效率,解析器使用一块临时存储区来保存中间结果。在解析多个 JSON 文本时,该存储区会被复用,从而减少内存分配的总次数,提升性能。构造解析器时,可指定用于此临时存储区分配的内存资源;若未指定,则使用默认内存资源。此外,解析器还可利用调用方提供的缓冲区作为临时存储,有助于避免对小型输入进行动态分配。以下示例为解析器提供了一个 4 KB 的临时缓冲区,并在需要时回退到默认内存资源: