跳到主要内容

std::scoped_allocator_adaptor<OuterAlloc,InnerAlloc...>::allocate

自 C++20 起
// 1)
[[nodiscard]] pointer allocate( size_type n );
// 2)
[[nodiscard]] pointer allocate( size_type n, const_void_pointer hint );
从 C++11 起,直到 C++20
// 1)
pointer allocate( size_type n );
// 2)
pointer allocate( size_type n, const_void_pointer hint );

使用外部分配器分配未初始化的存储。

  1. 调用 std::allocator_traits<OuterAlloc>::allocate(outer_allocator(), n)
  2. 此外,通过调用 std::allocator_traits<OuterAlloc>::allocate(outer_allocator(), n, hint) 提供内存局部性提示

参数

n - 要分配存储的对象数量
hint - 指向附近内存位置的指针

返回值

指向已分配存储的指针

std::scoped_allocator_adaptor<OuterAlloc,InnerAlloc...>::allocate

自 C++20 起
// 1)
[[nodiscard]] pointer allocate( size_type n );
// 2)
[[nodiscard]] pointer allocate( size_type n, const_void_pointer hint );
从 C++11 起,直到 C++20
// 1)
pointer allocate( size_type n );
// 2)
pointer allocate( size_type n, const_void_pointer hint );

使用外部分配器分配未初始化的存储。

  1. 调用 std::allocator_traits<OuterAlloc>::allocate(outer_allocator(), n)
  2. 此外,通过调用 std::allocator_traits<OuterAlloc>::allocate(outer_allocator(), n, hint) 提供内存局部性提示

参数

n - 要分配存储的对象数量
hint - 指向附近内存位置的指针

返回值

指向已分配存储的指针