向量有多少字节? [英] How many bytes does a vector have?
问题描述
亲爱的,
使用sizeof(vector< TYPE>)将始终返回16个字节。
如果我有N个元素(整数),
总内存是
sizeof(vector< int>)+ sizeof(int)* N,
或sizeof(vector< int>) * N,
或其他人?
感谢您的帮助。
最诚挚的问候,
cylin。
" cylin" < CY *** @ avant.com.tw>在消息中写道
新闻:2p ************ @ uni-berlin.de ...亲爱的,
使用sizeof(vector< TYPE>)将始终返回16个字节。
如果我有N个元素(整数),
总内存是
sizeof(vector< int>) + sizeof(int)* N,
或sizeof(vector< int>)* N,
或其他?
无法保证确定方式矢量正在使用的很多字节。
sizeof(vector< int>)+ sizeof(int)* N,
应该很漂亮关闭,提供N == capacity()而不是N == size()。向量的
容量是它为自己分配的存储量,这个
通常超过向量的大小。
John
" cylin" < CY *** @ avant.com.tw>在消息新闻中写道:< 2p ************ @ uni-berlin.de> ...亲爱的,
使用sizeof(vector< TYPE>)将始终返回16个字节。
如果我有N个元素(整数),则总内存为
sizeof(vector< int>)+ sizeof(int) * N,
或sizeof(vector< int>)* N,
或其他?
不是矢量使用的堆分配内存来存储它
elementes ??所以sizeof()实际上返回了
容器结构的(常量)大小,该结构内部有一个指向
堆分配的内存块的指针...... />
>没有保证的方法可以确定向量是多少字节
使用。这应该非常接近,提供N == capacity()而不是N == size( )。
向量的容量是它为自己分配的存储量,这通常超过向量的大小。
我怀疑函数保留。
例如:
向量< int> iVector,我向这个向量添加了100个元素。
iVector.capacity()= 128
iVector.size()= 100。
如果我使用iVector.reserve(iVector.size()),
然后iVector.capacity()= 128.
似乎没用。
Dear all,
Using sizeof(vector<TYPE>) will always return 16 bytes.
If I have N elements ( integer ),
the total memory is
sizeof(vector<int>)+sizeof(int)*N,
or sizeof(vector<int>)*N,
or others?
Thanks your help.
Best Regards,
cylin.
"cylin" <cy***@avant.com.tw> wrote in message
news:2p************@uni-berlin.de...Dear all,
Using sizeof(vector<TYPE>) will always return 16 bytes.
If I have N elements ( integer ),
the total memory is
sizeof(vector<int>)+sizeof(int)*N,
or sizeof(vector<int>)*N,
or others?
There is no guaranteed way of determining how many bytes a vector is using.
sizeof(vector<int>)+sizeof(int)*N,
That should be pretty close, providing N == capacity() not N == size(). The
capacity of a vector is how much storage it has allocated for itself, this
is often more than the size of the vector.
John
"cylin" <cy***@avant.com.tw> wrote in message news:<2p************@uni-berlin.de>...Dear all,
Using sizeof(vector<TYPE>) will always return 16 bytes.
If I have N elements ( integer ),
the total memory is
sizeof(vector<int>)+sizeof(int)*N,
or sizeof(vector<int>)*N,
or others?
isn''t it that the vector uses heap allocated memory to store its
elementes?? so sizeof() actually returns the (constant) size of the
container structure, which internally has a pointer to a
heap-allocated chunk of memory...
> There is no guaranteed way of determining how many bytes a vector is
using.That should be pretty close, providing N == capacity() not N == size(). The capacity of a vector is how much storage it has allocated for itself, this
is often more than the size of the vector.
I doubt about the function "reserve".
For example:
A vector<int> iVector, and I add 100 elements to this vector.
iVector.capacity()=128
iVector.size()=100.
If I use iVector.reserve(iVector.size()),
then iVector.capacity()=128.
It seems no use.
这篇关于向量有多少字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!