如何解决GCC用于STL的默认分配器是什么?
| 根据此链接,gcc提供了许多有趣的内存分配器以用于STL容器,但是如果我在创建std :: list时未指定一个,则默认使用该分配器?解决方法
就像您在该页面上说的那样,
分配器的当前默认选择是__gnu_cxx :: new_allocator。
即,默认分配器基本上只是
operator new
。
, 按照wiki的规定:\“默认分配器使用new运算符来分配内存。[13]通常将其实现为围绕C堆分配函数的薄层,[14]通常为不经常分配大内存块而优化\”
来自\“ ISO / IEC(2003)。ISO/ IEC 14882:2003(E):编程语言-C ++ \”(Wiki参考)
默认分配器:
namespace std {
template <class T> class allocator;
// specialize for void: template <> class allocator<void>
{
public:
typedef void* pointer;
typedef const void* const_pointer;
// reference-to-void members are impossible. typedef void value_type;
template <class U> struct rebind { typedef allocator<U> other; };
};
template <class T> class allocator
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T template value_type;
template <class U> struct rebind { typedef allocator<U> other;
};
allocator() throw();
allocator(const allocator&) throw();
template <class U> allocator(const allocator<U>&) throw();
̃allocator() throw();
pointer address(reference x) const;
const_pointer address(const_reference x) const;`
pointer allocate(
size_type,allocator<void>::const_pointer hint = 0);
void deallocate(pointer p,size_type n);
size_type max_size() const throw();
void construct(pointer p,const T& val);
void destroy(pointer p);
};
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。