分配但不使用分配器的标准图书馆设施 [英] Standard library facilities which allocate but don't use an Allocator
问题描述
In most places where the C++ standard library allocates memory, the user is able to customise this by providing a class which meets the Allocator
requirements. For example, almost all containers take an allocator template argument, and std::allocate_shared
returns a shared_ptr
whose contained element and control block are both allocated via a provided Allocator.
但是,在某些地方标准库可以(可能)分配内存,但是没有提供Allocator
支持.我能想到的是:
However, there are a few places where the standard library can (potentially) allocate memory, but no Allocator
support is provided. The ones I can think of are:
-
std::make_unique()
(没有相应的allocate_unique()
) -
std::any
-
std::function
(分配器支持将在C ++ 17中删除) -
std::valarray
-
std::basic_filebuf
(尽管std::basic_stringbuf
确实使用分配器) -
std::inplace_merge()
std::make_unique()
(no correspondingallocate_unique()
)std::any
std::function
(allocator support will be removed in C++17)std::valarray
std::basic_filebuf
(althoughstd::basic_stringbuf
does use an Allocator)std::inplace_merge()
问题:
- 我确定此列表不完整,但是我还错过了什么?
- 在非分配器的类和函数中,它们是否指定为使用全局
::operator new
,普通new
,还是未指定内存源? - 如果有人知道,为什么不提供
any
中的分配器支持并将其从function
中删除的原因是什么?
- I'm sure this list is incomplete, but what else have I missed?
- Of the non-Allocator classes and functions, are they specified to use global
::operator new
, plainnew
, or is the memory source unspecified? - If anybody knows, what are the reasons for not providing allocator support in
any
, and removing it fromfunction
?
推荐答案
不是详尽的列表.
-
<stdexcept>
中的所有内容,都需要分配内存来存储消息字符串. - 标准池/单调内存资源类显然分配了内存,但是它们是从另一个内存资源而不是分配器来分配内存的,因此从技术上讲它们适合您的描述.
-
boyer_moore_searcher
和boyer_moore_horspool_searcher
. - 几种
<algorithm>
算法试图获取额外的内存(例如stable_partition
,stable_sort
),并且所有并行算法(无论标头如何)都可能需要额外的内存. - 文件系统库中的许多内容:
-
path
;那个曾经在内部使用默认分配器的对象,但看起来似乎是最新的草案删除了该要求,尽管这似乎仍然是意图. -
directory_iterator
和recursive_directory_iterator
. - 一些可以构造临时
path
的文件系统操作.
- Everything in
<stdexcept>
, which needs to allocate memory to store the message string. - The standard pool/monotonic memory resource classes obviously allocate memory, but they do it from another memory resource, not an allocator, so they technically fit your description.
boyer_moore_searcher
andboyer_moore_horspool_searcher
.- Several
<algorithm>
algorithms attempt to obtain additional memory (e.g.,stable_partition
,stable_sort
) and all parallel algorithms (regardless of header) may need additional memory. - Many things in the filesystem library:
path
; that one used to use the default allocator internally, but looks like the newest draft removed that requirement, although it seems to be the intent still.directory_iterator
andrecursive_directory_iterator
.- Some filesystem operations that can construct temporary
path
s .
-
error_code::message()
,error_condition::message()
,error_category::message()
:这些返回一个string
,因此仅是默认分配器. -
bitset
的流插入运算符在概念上使用默认分配器调用to_string
,尽管实际上没有高质量的实现可以做到这一点. -
to_string
和to_wstring
空闲函数分别返回std::string
/std::wstring
;没有机会指定您自己的分配器.显然,string
的用户定义文字(例如"foo"s
)也没有自定义分配器支持. -
<locale>
中有多个方面,其成员函数返回std::string
或std::basic_string<charT>
,即使用默认分配器(例如,numpunct
),或仅接受basic_string<charT>
(例如,money_get
>). -
<random>
中的各种类型使用带有默认分配器的vector
.
error_code::message()
,error_condition::message()
,error_category::message()
: these return astring
, so default allocator only.bitset
's stream insertion operator notionally callsto_string
with the default allocator, though no high-quality implementation would do that in practice.- The
to_string
andto_wstring
free functions returnstd::string
/std::wstring
respectively; no chance to specify your own allocator. Obviously the user-defined literals forstring
(e.g.,"foo"s
) also have no custom allocator support. - There are several facets in
<locale>
that have member functions returning eitherstd::string
orstd::basic_string<charT>
, i.e., using the default allocator (e.g.,numpunct
), or accepting onlybasic_string<charT>
(e.g.,money_get
). - Various types in
<random>
uses avector
with the default allocator.
如果有人知道,不提供分配器的原因是什么? 是否支持
any
,并将其从function
中删除?If anybody knows, what are the reasons for not providing allocator support in
any
, and removing it fromfunction
?any
的分配器支持为无法实现.function
的分配器支持指定不当,并且困扰着问题.any
's allocator support is unimplementable.function
's allocator support is poorly specified and plagued with issues.这篇关于分配但不使用分配器的标准图书馆设施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-