GCC为STL使用的默认分配器是什么
What is the default allocator GCC uses for 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++"(维基参考)
默认分配器:
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);
};
}
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 如何使用默认参数等选择模板专业化
- 具有默认模板参数的多态类的模板推导失败
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 使用 std::分配器在 constexpr 中进行默认初始化
- 如何使用C 11样式非默认构造分配器指定初始大小
- 为什么我的自定义分配器比默认分配器慢
- 自定义分配器和默认成员
- 构造函数在哪里获取/设置默认分配器
- 除了默认分配器之外,stl现在还有其他分配器吗
- 使用分配器unordered_map非默认构造函数
- 带有容器和默认分配器的模板模板参数:我可以让我的声明更紧凑吗
- 应该分配器 construct() 默认初始化而不是值初始化
- 默认分配器将int清零
- 默认stl分配器如何分配
- 分配器作为向量和列表中的默认参数
- 如何创建c++ 11非默认构造分配器
- 替换默认的STL分配器
- GCC为STL使用的默认分配器是什么