Chinese (Simplified Han script) (Boost Json Translation - en to zh_Hans translation catalogue (59 entries)

en: = `storage_ptr` Variable-length containers in this library all use dynamically allocated memory to store their contents. Callers can gain control over the strategy used for allocation by specifying a <<ref_storage_ptr>> in select constructors and function parameter lists. A <<ref_storage_ptr>> has these properties:
zh_Hans: = `storage_ptr` 本库中的可变长度容器均使用动态分配的内存来存储其内容。调用方可通过在特定构造函数和函数参数列表中指定 &lt;<ref_storage_ptr>&gt; ，以控制所使用的内存分配策略。&lt;<ref_storage_ptr>&gt; 具有以下特性：</ref_storage_ptr></ref_storage_ptr>

en: A storage pointer always points to a valid,
zh_Hans: 存储指针始终指向一个有效的、

en: type-erased {ref_memory_resource}.
zh_Hans: 类型擦除后的 {ref_memory_resource}。

en: Default-constructed storage pointers reference the
zh_Hans: 默认构造的存储指针引用

en: <<default_memory_resource,default resource>>, an implementation-defined instance which always uses the equivalent of global operator new and delete.
zh_Hans: &lt;<default_memory_resource,default resource="">&gt;（默认资源），这是一个由实现定义的实例，始终使用等效于全局 operator new 和 operator delete 的方式。</default_memory_resource,default>

en: Storage pointers constructed from a {ref_memory_resource} or
zh_Hans: 从 {ref_memory_resource} 构造的存储指针，或

en: {ref_polymorphic_allocator} do not acquire ownership; the caller is responsible for ensuring that the lifetime of the resource extends until it is no longer referenced.
zh_Hans: 从 {ref_polymorphic_allocator} 构造的存储指针，不获取所有权；调用方负责确保资源的生命周期持续到不再被引用为止。

en: A storage pointer obtained from <<ref_make_shared_resource>> acquires shared
zh_Hans: 通过 &lt;<ref_make_shared_resource>&gt; 获取的存储指针会获得</ref_make_shared_resource>

en: ownership of the memory resource; the lifetime of the resource is extended until all copies of the storage pointer are destroyed.
zh_Hans: 对内存资源的共享所有权；该资源的生命周期将延长，直至所有该存储指针的副本均被销毁。

en: The storage pointer remembers the value of <<ref_is_deallocate_trivial>>
zh_Hans: 存储指针会记录 &lt;<ref_is_deallocate_trivial>&gt; 的值，</ref_is_deallocate_trivial>

en: before type-erasing the resource, allowing the value to be queried at run-time.
zh_Hans: （&lt;&gt; 值的记录是）在对资源进行类型擦除之前进行的,从而允许在运行时查询该值。

en: This lists all of the allocation-related types and functions available when using the library:
zh_Hans: 此列表列出了在使用该库时可用的所有与分配相关的类型和函数：

en: Description
zh_Hans: 描述

en: <<ref_get_null_resource>>
zh_Hans: &lt;&gt;

en: Returns a pointer to a memory resource instance which always throws an
zh_Hans: 返回一个指向内存资源实例的指针，该实例总是在

en: exception upon allocation. This is used to to achieve the invariant that no parsing or container operation will dynamically allocate memory.
zh_Hans: 分配内存时抛出异常。此机制用于确保解析或容器操作不会进行动态内存分配，从而维持该不变性。

en: <<ref_is_deallocate_trivial>>
zh_Hans: &lt;<ref_is_deallocate_trivial>&gt;</ref_is_deallocate_trivial>

en: A customization point allowing a memory resource type to indicate that calls
zh_Hans: 一个自定义点，允许内存资源类型表明其

en: to deallocate are trivial.
zh_Hans: deallocate 的调用是平凡的。

en: <<ref_make_shared_resource>>
zh_Hans: &lt;<ref_make_shared_resource>&gt;</ref_make_shared_resource>

en: A function returning a smart pointer with shared ownership of a newly
zh_Hans: 一个返回智能指针的函数，该智能指针对新

en: allocated memory resource.
zh_Hans: 分配的内存资源具有共享所有权。

en: The abstract base class representing an allocator.
zh_Hans: 表示分配器的抽象基类。

en: <<ref_monotonic_resource>>
zh_Hans: &lt;<ref_monotonic_resource>&gt;</ref_monotonic_resource>

en: A memory resource which allocates large blocks of memory and has a trivial
zh_Hans: 一种内存资源，用于分配大块内存，且该资源具有平凡的

en: deallocate function. Allocated memory is not freed until the resource is destroyed, making it fast for parsing but not suited for performing modifications.
zh_Hans: deallocate 函数。所分配的内存不会被释放，直到该资源被销毁，因此在解析场景下速度很快，但不适合执行修改操作。

en: An {req_Allocator} which uses a reference to a {ref_memory_resource} to
zh_Hans: 一个 {req_Allocator}，它通过引用 {ref_memory_resource}

en: perform allocations.
zh_Hans: 执行内存分配。

en: <<ref_static_resource>>
zh_Hans: &lt;<ref_static_resource>&gt;</ref_static_resource>

en: A memory resource that uses a single caller provided buffer. No dynamic
zh_Hans: 一种使用调用方提供的单一缓冲区的内存资源，不进行任何动态

en: allocations are used. This is fast for parsing but not suited for performing modifications.
zh_Hans: 分配。该资源在解析时速度很快，但不适合执行修改操作。

en: <<ref_storage_ptr>>
zh_Hans: &lt;<ref_storage_ptr>&gt;</ref_storage_ptr>

en: accessed. |===
zh_Hans: 访问. |===

en: Default Memory Resource
zh_Hans: 默认内存资源

en: The default memory resource uses the global `operator new` and `operator delete` to allocate memory. This resource is not reference counted and has a non-trivial deallocate function. All default-constructed <<ref_storage_ptr>> objects reference the same memory resource:
zh_Hans: 默认内存资源使用全局 `operator new` 和 `operator delete` 来进行内存分配。该资源不采用引用计数，且其 deallocate 函数是非平凡的。所有默认构造的 &lt;<ref_storage_ptr>&gt; 对象均引用同一个内存资源：</ref_storage_ptr>

en: Default-constructed library containers use the default memory resource:
zh_Hans: 默认构造的库容器使用默认内存资源：

en: The default memory resource is well suited for general usage. It offers reasonable performance for parsing, and conservative memory usage for modification of the contents of containers.
zh_Hans: 默认内存资源适用于一般用途。它在解析时提供合理的性能，在修改容器内容时则具有保守的内存使用特性。

en: This memory resource is not guaranteed to be the same as the result of `boost::container::pmr::get_default_resource`. It also cannot be changed with `boost::container::pmr::set_default_resource`.
zh_Hans: 该内存资源不保证与 `boost::container::pmr::get_default_resource` 的返回结果相同，也无法通过 `boost::container::pmr::set_default_resource` 进行更改。

en: Monotonic Resource
zh_Hans: 单调资源

en: Consider the pattern of memory allocation during parsing: when an array, object, or string is encountered the parser accumulates elements in its temporary storage area. When all of the elements are known, a single memory allocation is requested from the resource when constructing the value. Thus, parsing only allocates and constructs containers at their final size. Memory is not reallocated; that is, a memory buffer never needs to grow by allocating a new larger buffer and deallocating the previous buffer.
zh_Hans: 考虑解析过程中的内存分配模式：当遇到数组、对象或字符串时，解析器会将其元素累积在临时存储区中。当所有元素都已知后，在构造值时会向内存资源发起一次内存分配请求。因此，解析过程仅在容器最终大小确定时进行一次分配和构造，不会发生内存重分配；也就是说，内存缓冲区无需通过分配更大的新缓冲区并释放旧缓冲区的方式来扩容。

en: The <<ref_monotonic_resource>> optimizes this memory allocation pattern by allocating increasingly large blocks of global memory internally and parceling those blocks out in smaller pieces to fulfill allocation requests. It has a trivial deallocate function. The monotonic resource does not actually deallocate memory until the resource is destroyed. Thus, it is ideally suited for the use-case where JSON is parsed, and the resulting value is then inspected but not modified.
zh_Hans: &lt;<ref_monotonic_resource>&gt; 通过在内部分配逐渐增大的全局内存块，并将这些块切分为更小的部分以满足分配请求，从而优化了该内存分配模式。它具有平凡的 deallocate 函数，实际上不会释放内存，直到该资源被销毁。因此，它非常适合用于解析 JSON 后仅检查结果值而不对其进行修改的场景。</ref_monotonic_resource>

en: The resource to use when constructing values may be specified in calls to <<ref_parse>> as shown here:
zh_Hans: 在调用 &lt;<ref_parse>&gt; 时，可按如下方式指定构造值所使用的内存资源：</ref_parse>

en: Or, to parse into a value with shared ownership of the memory resource:
zh_Hans: 或者，可按如下方式解析到一个对内存资源具有共享所有权的值：

en: A monotonic resource may be optionally constructed with an initial buffer to use first, before going to the heap. This allows the caller to use stack space and avoid dynamic allocations for most parsed JSON, falling back to dynamic allocation from the heap if the input JSON is larger than average, as shown here:
zh_Hans: 单调资源在构造时可选择性地指定一个初始缓冲区，优先使用该缓冲区，之后才会转而使用堆内存。这使得调用方可以利用栈空间，避免对大多数 JSON 解析进行动态分配；仅当输入的 JSON 大于平均水平时，才会退回到从堆中进行动态分配，如下所示：

en: Static Resource
zh_Hans: 静态资源

en: A <<ref_static_resource>> constructs from a caller-provided buffer, and satisfies all memory allocation requests from the buffer. Once the buffer is exhausted, subsequent calls to allocate throw the exception `std::bad_alloc`. The resource offers a simple invariant: dynamic heap allocations are never performed.
zh_Hans: &lt;<ref_static_resource>&gt; 由调用方提供的缓冲区构造而成，并从该缓冲区满足所有内存分配请求。一旦缓冲区耗尽，后续的分配调用将抛出 `std::bad_alloc` 异常。该资源提供一个简单的不变式：永不执行动态堆分配。</ref_static_resource>

en: To use the resource, construct it with a local buffer:
zh_Hans: 要使用该资源，请用一个局部缓冲区对其进行构造：

en: Null Resource
zh_Hans: 空资源

en: The function <<ref_get_null_resource>> returns a global instance of the null resource. This resource offers a simple invariant: all calls to allocate will throw the exception `std::bad_alloc`. An instance of the null resource can be used to make parsing guarantee that allocations from the heap are never made. This is explored in more detail in a later section.
zh_Hans: 函数 &lt;<ref_get_null_resource>&gt; 返回一个全局的空资源实例。该资源提供一个简单的不变式：所有内存分配调用都会抛出 `std::bad_alloc` 异常。通过使用空资源实例，可确保解析过程绝不会进行堆内存分配。这一点将在后文进一步详细说明。</ref_get_null_resource>

en: Allocator Propagation
zh_Hans: 分配器传播

en: The containers <<ref_array>>, <<ref_object>>, and <<ref_value>> all propagate the memory resource they were constructed with to child elements:
zh_Hans: 容器 &lt;<ref_array>&gt;, &lt;<ref_object>&gt; 和 &lt;<ref_value>&gt; 在构造时所使用的内存资源会自动传播给其子元素：</ref_value></ref_object></ref_array>

en: This propagation acts recursively, containers within containers will all have the resource propagated. Once a container is constructed, its memory resource can never be changed.
zh_Hans: 这种传播是递归进行的：嵌套容器中的所有子容器都会获得相同的内存资源。一旦容器被构造，其内存资源就永远无法更改。

en: Resource Lifetime
zh_Hans: 资源生命周期

en: It is important to note that <<ref_storage_ptr>> supports both shared-ownership and reference lifetime models. Construction from a memory resource pointer does not transfer ownership:
zh_Hans: 需要注意的是，&lt;<ref_storage_ptr>&gt; 同时支持共享所有权和引用生命周期模型。从内存资源指针构造时不会转移所有权：</ref_storage_ptr>

en: When using a memory resource in this fashion, including the case where a storage pointer or container is constructed from a {ref_polymorphic_allocator}, the caller must ensure that the lifetime of the resource is extended until it is no longer referenced by any variables; otherwise, undefined behavior is possible.
zh_Hans: 以这种方式使用内存资源时（包括从 {ref_polymorphic_allocator} 构造存储指针或容器的情况），调用方必须确保资源的生命周期延长至不再被任何变量引用为止；否则，可能会出现未定义行为。

en: Shared ownership is achieved using the function <<ref_make_shared_resource>>, which creates a new, reference-counted memory resource using a dynamic memory allocation and returns it as a <<ref_storage_ptr>>:
zh_Hans: 通过函数 &lt;<ref_make_shared_resource>&gt; 可实现共享所有权，该函数会动态分配内存以创建一个新的、带引用计数的内存资源，并将其以 &lt;<ref_storage_ptr>&gt; 的形式返回：</ref_storage_ptr></ref_make_shared_resource>

en: When a storage pointer is constructed this way, the lifetime of the referenced memory resource is extended until all variables which reference it are destroyed.
zh_Hans: 当存储指针以这种方式构造时，其所引用的内存资源的生命周期将延长，直至所有引用它的变量均被销毁为止。

en: User-Defined Resource
zh_Hans: 用户定义资源

en: To implement custom memory allocation strategies, derive your class from {ref_memory_resource} and implement the functions `do_allocate`, `do_deallocate`, and `do_is_equal` as seen in this example below, which logs each operation it performs to the console:
zh_Hans: 要实现自定义内存分配策略，请从 {ref_memory_resource} 派生类，并实现函数 `do_allocate`、`do_deallocate` 和 `do_is_equal`，如下例所示，该示例将其执行的每个操作记录到控制台：
