STLvector中的get_allocator方法(27)
原文地址:http://www.cplusplus.com/reference/vector/vector/get_allocator/
public member function
std::vector::get_allocator
- C++98
- C++11
allocator_type get_allocator() const noexcept;
Get allocator
Returns a copy of the allocator object associated with the vector.
返回vector的内存分配器。
//这个有人说我们初学者基本不会用到,我觉得也的确是,因此,现阶段我们就只是了解好了。
Parameters
none
Return Value
The allocator.
返回值是一个内存分配器对象。
Member type allocator_type is the type of the allocator used by the container, defined in vector as an alias of its second template parameter (Alloc).
其类型由vector模版参数Alloc指定。
Example
1 | 1 |
1 | // vector::get_allocator |
The example shows an elaborate way to allocate memory for an array of ints using the same allocator used by the vector. Output:
The allocated array contains: 0 1 2 3 4
这个例子详细说明了array分配内存的过程。
运行截图:
Complexity
Constant.
Iterator validity
No changes.
Data races
The container is accessed.容器将被访问。
No contained elements are accessed: concurrently accessing or modifying them is safe.
容器内的元素不会被访问。同时访问以及修改他们都是安全的。
Exception safety
No-throw guarantee: this member function never throws exceptions.该方法不会i抛出异常。
Copying any instantiation of the default allocator is also guaranteed to never throw.复制任何实例化的默认构造器也不会抛出异常。
//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
2014-8-17
于GDUT
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/stlvector中的get-allocator方法27/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!