C++ 0x分配器

Moo*_*uck 6 scope allocator visual-c++ c++11

我观察到我的MSVC10副本带有似乎允许基于状态的分配器的容器,并编写了一个简单的池分配器,为特定类型分配池.但是,我发现如果_ITERATOR_DEBUG_LEVEL != 0MSVC向量从传递的分配器创建代理分配器(用于迭代器跟踪?),则使用代理,然后让代理超出范围,期望分配的内存保留.这会导致问题,因为我的分配器尝试在销毁时释放它的池.这是否允许C++ 0x标准?

代码大致如下:

class _Container_proxy{};

template<class T, class _Alloc>
class vector {
     _Alloc _Alval;
public: 
    vector() {
        // construct _Alloc<_Container_proxy> _Alproxy
         typename _Alloc::template rebind<_Container_proxy>::other 
                 _Alproxy(_Alval);
        //allocate
        this->_Myproxy = _Alproxy.allocate(1);
        /*other stuff, but no deallocation*/
    } //_Alproxy goes out of scope

    ~_Vector_val() {    // destroy proxy
        // construct _Alloc<_Container_proxy> _Alproxy
        typename _Alloc::template rebind<_Container_proxy>::other
                 _Alproxy(_Alval);
        /*stuff, but no allocation*/
        _Alproxy.deallocate(this->_Myproxy, 1);
    } //_Alproxy goes out of scope again
Run Code Online (Sandbox Code Playgroud)

Nic*_*las 3

根据第 17.6.3.5 节中的分配器要求巨表,分配器必须是可复制的。容器可以自由复制它们。因此,您需要将池存储在 astd::shared_ptr或类似的东西中,以防止在其中一个分配器存在时被删除。