在正在运行的程序中,如何跟踪/打印对象已分配的堆内存量?有没有办法打印对象已分配的堆内存量?
例如:
#include <iostream>
#include <vector>
int main(){
std::vector<int> v;
std::cout << heap_sizeof(v) << '\n';
for (int i = 0; i < 1000; ++i){
v.push_back(0);
}
std::cout << heap_sizeof(v) << '\n';
}
是否有可替代heap_sizeof()
的实现?
在一般情况下,只针对特定平台。它与堆的实现非常相关。 –
谁应该shared_ptr <>的数量为? – lorro
'std :: cout << sizeof(int)* v.capacity()<< endl;' – GreatAndPowerfulOz