msgid ""
msgstr ""
"Project-Id-Version: Chinese (Simplified Han script) (Boost Json Translation "
"(zh_Hans))\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-06-06 21:31+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: Chinese (Simplified Han script) <https://"
"insights.cppalliance.org/weblate/projects/boost-json-documentation-zh_Hans/"
"doc-pages-allocators-background-adoc/zh_Hans/>\n"
"Language: zh_Hans\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Weblate 2026.5\n"

#: :11
#, safe-html, strict-same
msgid ""
"= Background The first version of allocators in C++ defined the named "
"requirement {req_Allocator}, and made each standard container a class "
"template parameterized on the allocator type. For example, here is the "
"declaration for {std_vector}:"
msgstr ""
"= 背景 C++中分配器的第一个版本定义了名为{req_Allocator}的要求，并将每个标准容"
"器设计为以分配器类型为模板参数的类模板。例如，以下是 {std_vector} 的声明："

#: :22
#, safe-html, strict-same
msgid ""
"The standard allocator is {req_DefaultConstructible}. To support stateful "
"allocators, containers provide additional constructor overloads taking an "
"allocator instance parameter."
msgstr ""
"标准分配器是{req_DefaultConstructible}。为支持有状态分配器，容器提供了额外的"
"构造函数重载，接受一个分配器实例参数。"

#: :31
#, safe-html, strict-same
msgid "While the system works, it has some usability problems:"
msgstr "尽管该机制能够正常工作，但仍存在一些可用性问题："

#: :33
#, safe-html, strict-same
msgid "The container must be a class template."
msgstr "容器必须是一个类模板。"

#: :34
#, safe-html, strict-same
msgid "Parameterizing the allocator on the element type is clumsy."
msgstr "在元素类型上参数化分配器的方式显得笨拙。"

#: :35
#, safe-html, strict-same
msgid "The system of allocator traits, especially POCCA and POCMA,"
msgstr "分配器特征机制，尤其是 POCCA 和 POCMA，"

#: :36
#, safe-html, strict-same
msgid "is complicated and error-prone."
msgstr "是复杂且容易出错的。"

#: :38
#, safe-html, strict-same
msgid ""
"Allocator-based programs which use multiple allocator types incur a greater "
"number of function template instantiations and are generally slower to "
"compile because class template function definitions must be visible at all "
"call sites."
msgstr ""
"使用多种分配器类型的基于分配器的程序会引发更多的函数模板实例化，且通常编译速"
"度更慢，因为类模板的函数定义必须在所有调用点可见。"

#: :42
#, safe-html, strict-same
msgid "Polymorphic Allocators"
msgstr "多态分配器"

#: :44
#, safe-html, strict-same
msgid ""
"{cpp}17 improves the allocator model by representing the low-level "
"allocation operation with an abstract interface called {ref_memory_resource}"
", which is not parameterized on the element type, and has no traits:"
msgstr ""
"{cpp}17通过引入一个名为 {ref_memory_resource} 的抽象接口来表示底层分配操作，"
"从而改进分配器模型。该接口未在元素类型上参数化，且无特征："

#: :53
#, safe-html, strict-same
msgid ""
"The class template {ref_polymorphic_allocator} wraps a {ref_memory_resource} "
"pointer and meets the requirements of {req_Allocator}, allowing it to be "
"used where an allocator is expected. The standard provides type aliases "
"using the polymorphic allocator for standard containers:"
msgstr ""
"类模板{ref_polymorphic_allocator}包装了{ref_memory_resource}指针，并满足"
"{req_Allocator}要求，使其可在需要分配器的地方使用。标准库为使用多态分配器的标"
"准容器提供了类型别名："

#: :63
#, safe-html, strict-same
msgid "A polymorphic allocator constructs with a pointer to a memory resource:"
msgstr "多态分配器通过一个指向内存资源的指针进行构造："

#: :70
#, safe-html, strict-same
msgid ""
"The memory resource is passed by pointer; ownership is not transferred. The "
"caller is responsible for extending the lifetime of the memory resource "
"until the last container which is using it goes out of scope, otherwise the "
"behavior is undefined. Sometimes this is the correct model, such as in this "
"example which uses a monotonic resource constructed from a local stack "
"buffer:"
msgstr ""
"内存资源通过指针传递；所有权不发生转移。调用方需负责确保该内存资源的生命周期"
"持续到所有使用它的容器都离开作用域为止，否则行为未定义。在某些场景下，这种模"
"型是合适的，例如以下示例中使用了一个基于局部栈缓冲区构造的单调内存资源："

#: :81
#, safe-html, strict-same
msgid ""
"However, sometimes shared ownership is needed. Specifically, that the "
"lifetime extension of the memory resource should be automatic. For example, "
"if a library wants to return a container which owns an instance of the "
"library's custom memory resource as shown below:"
msgstr ""
"然而，有时需要共享所有权，即内存资源的生命周期应自动延长。例如，若某个库希望"
"返回一个容器，该容器拥有该库自定义内存资源的实例，如下所示："

#: :91
#, safe-html, strict-same
msgid ""
"This can be worked around by declaring the container to use a custom "
"allocator (perhaps using a `std::shared_ptr< std::pmr::memory_resource >` as "
"a data member). This hinders library composition; every library now exports "
"unique, incompatible container types. A raw memory resource pointer is also "
"easy to misuse:"
msgstr ""
"可通过声明容器使用自定义分配器（可能使用`std::shared_ptr&lt; "
"std::pmr::memory_resource &gt;`作为数据成员）来解决此问题。这会阻碍库的组合；"
"每个库都会导出各自独特且互不兼容的容器类型。原始内存资源指针也容易被误用："

#: :102
#, safe-html, strict-same
msgid ""
"Workarounds for this problem are worse than the problem itself. The library "
"could return a pair with the vector and "
"`std::unique_ptr<std::pmr::memory_resource>` which the caller must manage. "
"Or the library could change its function signatures to accept a "
"{ref_memory_resource}``*`` provided by the caller, where the library also "
"makes public the desired memory resources (`my_resource` above)."
msgstr ""
"针对此问题的变通方案往往比问题本身更糟糕。该库可以返回一个包含 vector "
"和`std::unique_ptr<std::pmr::memory_resource>`的pair，必须由调用方自行管理。"
"或者，该库也可以修改其函数签名，接受调用方提供的{ref_memory_resource}``*``，"
"同时将所需的内存资源（如上文的`my_resource`）公开。</"
"std::pmr::memory_resource>"

#: :109
#, safe-html, strict-same
msgid "Problem Statement"
msgstr "问题陈述"

#: :111
#, safe-html, strict-same
msgid ""
"We would like an allocator model using a single type `T` with the following "
"properties:"
msgstr "我们希望采用一种使用单一类型`T`的分配器模型，该模型具有以下特性："

#: :114
#, safe-html, strict-same
msgid "`T` is not a class template"
msgstr "`T`不是类模板"

#: :115
#, safe-html, strict-same
msgid "`T` references a {ref_memory_resource}"
msgstr "`T`引用一个 {ref_memory_resource}"

#: :116
#, safe-html, strict-same
msgid "`T` supports both reference semantics or shared ownership"
msgstr "`T`同时支持引用语义和共享所有权"

#: :117
#, safe-html, strict-same
msgid "`T` interoperates with code already using `std::pmr`"
msgstr "`T`能与已使用`std::pmr`的代码互操作"

#: :119
#, safe-html, strict-same
msgid ""
"Boost.JSON solves this problem by introducing a new smart pointer called "
"<<ref_storage_ptr>> which builds upon {cpp}17's memory allocation "
"interfaces, accomplishing the goals above. As a result, libraries which use "
"this type compose more easily and enjoy faster compilation, as member "
"functions for containers which use the type can be defined out-of-line."
msgstr ""
"Boost.JSON通过引入一个名为&lt;<ref_storage_ptr>&gt; 的新型智能指针解决此问题"
"，该指针基于{cpp}17的内存分配接口构建，实现了上述目标。因此，使用该类型的库更"
"易于组合，并能获得更快的编译速度，因为使用该类型的容器的成员函数可以定义在类"
"外（out-of-line）。</ref_storage_ptr>"
