拥有一个空向量与拥有一个指向向量的指针的内存开销是多少?
What is the memory overhead of having an empty vector vs having a pointer to a vector?
选项 A:
std::vector<int> v;
选项 B:
std::vector<int> *v = NULL;
我相信选项 B 需要 1 个 32 位指针(假设这里是 32 位)空的v"占用多少内存?
I believe that option B takes 1 32 bit pointer (assuming 32 bit here) How much memory does the empty 'v' take up?
至于问的问题:看实现.使用 MSVC 7.1:
As for the question as asked: It depends on the implementation. With MSVC 7.1 this:
std:: cout << sizeof(std::vector<int>) << std::endl;
给我 16(字节).(3个指针:容量的开始、结束和结束,加上一个分配器)
gives me 16 (bytes). (3 pointers: begin, end, and end of capacity, plus an allocator)
然而应该注意的是,指向向量的指针给了它更大的开销:
However it should be noted that the pointer-to-vector gives it a larger overhead:
这篇关于空向量的开销成本是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
fpermissive 标志有什么作用?What does the fpermissive flag do?(fpermissive 标志有什么作用?)
如何在我不想编辑的第 3 方代码中禁用来自 gccHow do you disable the unused variable warnings coming out of gcc in 3rd party code I do not wish to edit?(如何在我不想编辑的第 3 方代码中禁
使用 GCC 预编译头文件Precompiled headers with GCC(使用 GCC 预编译头文件)
如何在 OS X 中包含 omp.h?How to include omp.h in OS X?(如何在 OS X 中包含 omp.h?)
如何让 GCC 将 .text 部分编译为可写在 ELF 二进制文How can I make GCC compile the .text section as writable in an ELF binary?(如何让 GCC 将 .text 部分编译为可写在 ELF 二进制文件中?)
GCC、字符串化和内联 GLSL?GCC, stringification, and inline GLSL?(GCC、字符串化和内联 GLSL?)