简体   繁体   English

编译器支持STL容器中的有状态分配器

[英]compiler support for stateful allocators in STL containers

The new C++11 standard requires STL implementations to support stateful allocators in containers. 新的C ++ 11标准要求STL实现支持容器中的有状态分配器。 Do main STL implementations (Visual Studio 2008, 2010, libstdc++) comply to this requirement now? 主STL实现(Visual Studio 2008,2010,libstdc ++)现在是否符合此要求? I found nothing about this in MSDN or in libstdc++ documentation. 我在MSDN或libstdc ++文档中找不到任何相关内容。

Looks like the feature of stateful allocators in STL containers is widely supported already. 看起来STL容器中的有状态分配器的功能已经得到广泛支持。 In most cases statefullness of the allocator does not cause trouble. 在大多数情况下,分配器的完整性不会造成麻烦。 What is not widely supported yet is the new standard's way of handling the problematic situations (swap of a container(whether to swap the allocator too), splice of lists). 尚未得到广泛支持的是新标准处理有问题情况的方式(交换容器(是否交换分配器),列表拼接)。

This thread says: 这个帖子说:

in code for most current standard libraries (including Dinkumware's as used by MS), stateful allocators are supported 在大多数当前标准库(包括MS使用的Dinkumware)的代码中,支持有状态分配器

This tread (libstdc++, 2004) says (if i understood correctly): 这个步骤 (libstdc ++,2004)说(如果我理解正确的话):

We already support allocators where l1.get_allocator() != l2.get_allocator() . 我们已经支持l1.get_allocator() != l2.get_allocator()分配器。 What we don't do is make any special provisions to detect those allocators in splice() and swap() . 我们不做的是做出任何特殊规定来检测splice()swap()那些分配器。

This blog entry (libstdc++, 2009) says: 这篇博客文章 (libstdc ++,2009)说:

Existing containers in C++0x mode are now more efficient together with stateful allocators (ie, no allocators are created on the fly at element construction time). 现在,C ++ 0x模式下的现有容器与有状态分配器一起使用效率更高(即,在元素构建时不会动态创建分配器)。

This document says about the new libc++ library : 本文档介绍了新的libc ++库

All containers meet all of the latest allocator requirements which fully support stateful allocators. 所有容器都满足所有最新的分配器要求,这些要求完全支持有状态分配器。 – Space for stateless allocators optimized away. - 无状态分配器的空间被优化掉了。

EASTL supports statefull allocators. EASTL支持有状态分配器。

This thread contains an interesting dispute about how portable this feature is. 该主题包含有关此功能的可移植性的有趣争议。

So most STL implementations support statefull allocators, which means that they do not create additional instances of the allocator type under the hood, but store the client-supplied allocator instance and all allocations/deallocations are done via that. 因此大多数STL实现都支持statefull分配器,这意味着它们不会在引擎盖下创建分配器类型的其他实例,而是存储客户端提供的分配器实例,并且所有分配/解除分配都是通过它完成的。 However the way that they handle swap ping and list::splice is undocumented, non-portable. 但是,它们处理swap ping和list::splice是未记录的,不可移植的。

UPDATE: VS2008's STL requires the allocators to have the templated copy constructor, which IMO makes the most important use of custom allocators impossible: simple segregated storage. 更新:VS2008的STL要求分配器具有模板化的复制构造函数,IMO最不可能使用自定义分配器:简单的隔离存储。

For whoever is not satisfied with the current state of stateful allocators in STL, I recommend to consider Boost.Intrusive and Boost.Container . 对于对STL中有状态分配器的当前状态不满意的人,我建议考虑Boost.IntrusiveBoost.Container

g++ does not support scoped allocators yet. g ++ 还不支持作用域分配器。

VS2010 supportes certain non-standard allocators but not apparently the standard ones VS2010支持某些非标准分配器, 但显然不支持标准分配器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM