跳到主要内容

std::pmr::polymorphic_allocator<T>::allocate_bytes

自 C++20 起
[[nodiscard]] void* allocate_bytes( std::size_t nbytes,
std::size_t alignment = alignof(std::max_align_t) );

使用底层内存资源,在指定对齐方式 alignment 下分配 nbytes 字节的存储空间。
等同于 return resource()->allocate(nbytes, alignment);

参数

nbytes - 要分配的字节数
alignment - 要使用的对齐方式

返回值

指向已分配存储空间的指针。

备注

此函数是为完全特化的分配器 std::pmr::polymorphic_allocator<> 而引入的,但它也可以用于任何特化。

返回类型是 void*(而不是,例如,std::byte*),以便通过 static_cast<U*> 转换为任意指针类型 U*。

异常

可能会抛出调用 resource()->allocate 时抛出的任何异常。

std::pmr::polymorphic_allocator<T>::allocate_bytes

自 C++20 起
[[nodiscard]] void* allocate_bytes( std::size_t nbytes,
std::size_t alignment = alignof(std::max_align_t) );

使用底层内存资源,在指定对齐方式 alignment 下分配 nbytes 字节的存储空间。
等同于 return resource()->allocate(nbytes, alignment);

参数

nbytes - 要分配的字节数
alignment - 要使用的对齐方式

返回值

指向已分配存储空间的指针。

备注

此函数是为完全特化的分配器 std::pmr::polymorphic_allocator<> 而引入的,但它也可以用于任何特化。

返回类型是 void*(而不是,例如,std::byte*),以便通过 static_cast<U*> 转换为任意指针类型 U*。

异常

可能会抛出调用 resource()->allocate 时抛出的任何异常。