c++11 动态内存管理-分配器 (std::allocator)

定义于头文件 <memory>
template< class T >struct allocator;   (1)  

template<>struct allocator<void>; (2) (C++17 中弃用) (C++20 中移除) 

std::allocator 类模板是所有标准库容器所用的默认分配器 (Allocator) ,若不提供用户指定的分配器。默认分配器无状态,即任何给定的 allocator 实例可交换、比较相等,且能解分配同一 allocator 类型的任何其他实例所分配的内存。

对 void 的显式特化缺少成员 typedef referenceconst_referencesize_typedifference_type 。此特化不声明成员函数。

(C++20 前)
所有自定义分配器必须也无状态。 (C++11 前)
自定义分配器可以含有状态。每个容器或其他具分配器对象存储一个提供的分配器实例,并通过 std::allocator_traits 控制分配器替换。 (C++11 起)
默认分配器满足分配器完整性要求。 (C++17 起)

构造函数 

std::allocator<T>::allocator

allocator() throw();

(1) (C++11 前)

allocator() noexcept;

(C++11 起)
(C++20 前)

constexpr allocator() noexcept;

(C++20 起)

allocator( const allocator& other ) throw();

(2) (C++11 前)

allocator( const allocator& other ) noexcept;

(C++11 起)
(C++20 前)

constexpr allocator( const allocator& other ) noexcept;

(C++20 起)

template< class U >
allocator( const allocator<U>& other ) throw();

(3) (C++11 前)

template< class U >
allocator( const allocator<U>& other ) noexcept;

(C++11 起)
(C++20 前)

template< class U >
constexpr allocator( const allocator<U>& other ) noexcept;

(C++20 起)

构造默认分配器。因为默认分配器是无状态的,故构造函数无可见效应。

参数

other - 用以构造的另一 allocator

 

析构函数

std::allocator<T>::~allocator
<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值