简体   繁体   English

默认矢量存储大小

[英]Default vector memory size

向量应该是动态增长的,并且具有连续的内存位置,这是通过使用allocator类的operator new获得的。我的问题是,默认情况下,默认向量(当我们未指定保留大小时)使用new分配多少内存,因此它可以成长并在以后添加元素。

It's implementation defined (ie may differ between multiple compilers). 它的实现已定义(即,在多个编译器之间可能有所不同)。

The total amount of allocated memory can be queried using std::vector::capacity() function. 可以使用std::vector::capacity()函数查询已分配的内存总量。


To read on, check out this post: size vs capacity of a vector? 要继续阅读,请查看这篇文章: 大小与向量的容量? .

That is up to the implementation, and you have no way to know. 这取决于实现,您无法知道。 Actually, even if you specify a size to reserve, the implementation is free to reserve however much it pleases (the size is just a hint, AFAIK). 实际上,即使您指定要保留的大小,实现也可以自由地保留它所需要的任何大小(该大小只是一个提示,即AFAIK)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM