當我用「擦除」刪除矢量中的元素時,則沒有清除內存。例如,我製作了一個尺寸爲2000的矢量。創建之後,程序使用1.5 MB內存。當我進行擦除調用時,什麼都不會被清除。所有的元素都消失了。但他們仍在記憶中。如何刪除矢量中的元素。 (擦除將不起作用)
例如:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
//Makes a vector of 2000 items
vector<int> test(200000);
//Pause for test purpose
system("pause");
//erase all elements
test.erase(test.begin(),test.end());
//Pause for test purpose
system("pause");
return false;
}
尺寸返回0。但是,這一過程仍然使用的存儲器1,5MB。
你如何測量進程正在使用的內存? – 2012-02-15 07:52:27
也許你應該閱讀: http://stackoverflow.com/questions/586634/shrinking-a-vector 希望它能幫助。 – 2012-02-15 07:54:40