std::allocator::allocate
pointer allocate( size_type n, std::allocator<void>::const_pointer hint = 0 ); | (1) | (until C++17) |
---|---|---|
T* allocate( std::size_t n, const void * hint); | (1) | (since C++17) (deprecated) |
T* allocate( std::size_t n ); | (2) | (since C++17) |
分配n * sizeof(T)
调用未初始化存储的字节::operator new(std::size_t)
,但未指定何时以及如何调用此函数。指针hint
可用于提供引用的局部性:如果实现支持分配程序,则将尝试将新的内存块分配到hint
...
参数
n | - | the number of objects to allocate storage for |
---|---|---|
hint | - | pointer to a nearby memory location |
返回值
指向内存块的第一个字节的指针,其对齐适当,足以容纳n
类型对象T
...
例外
抛出std::bad_alloc
如果分配失败。
注记
另见
allocate static | allocates uninitialized storage using the allocator (public static member function of std::allocator_traits) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com