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