首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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如果分配失败。

注记

“未具体说明时间和方式”的措辞使得有可能组合或优化堆分配由标准库容器进行,即使这种优化不允许直接调用::operator new例如,这是由libc++%28实现的。[1][2]29%。

另见

allocate static

allocates uninitialized storage using the allocator (public static member function of std::allocator_traits)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com