std::allocator_traits::allocate

定义于头文件 <memory>
(1)
static pointer allocate( Alloc& a, size_type n );
(C++11 起)
(C++20 前)
[[nodiscard]] static pointer allocate( Alloc& a, size_type n );
(C++20 起)
(2)
static pointer allocate( Alloc& a, size_type n,
                         const_void_pointer hint );
(C++11 起)
(C++20 前)
[[nodiscard]] static pointer allocate( Alloc& a, size_type n,
                                       const_void_pointer hint );
(C++20 起)

用分配器 a 分配 n*sizeof(Alloc::value_type) 字节的未初始化存储。

1) 调用 a.allocate(n)
2) 附带地传递内存位置提示 hint 。若可能则调用 a.allocate(n, hint) 。若不可能(例如无双参数成员函数 allocate() ),则调用 a.allocate(n)

参数

a - 使用的分配器
n - 要分配存储的对象数
hint - 指向临近内存位置的指针

返回值

调用 a.allocate(n) 所返回的指针。

参阅

分配未初始化的存储
(std::allocator 的公开成员函数)

版本历史

  • (当前 | 先前 2017年11月13日 (一) 16:17Fruderica讨论 | 贡献 . . (1,294字节) (+288). . (P0600R1 nodiscard) (撤销)
  • 当前 | 先前 2017年6月4日 (日) 19:12Fruderica讨论 | 贡献. . (1,006字节) (-1,064). . (撤销)
  • 当前 | 先前 2013年7月2日 (二) 09:01P12bot讨论 | 贡献 . . (2,070字节) (-145). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 16:49P12bot讨论 | 贡献 . . (2,215字节) (+353). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 03:25P12讨论 | 贡献 . . (1,862字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (1,862字节) (-55). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:09P12讨论 | 贡献 . . (1,917字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (1,917字节) (+1,917). . (Translated from the English version using Google Translate)