我想使用 std::deque,但是消耗的内存开销似乎太大了。我做错了什么吗?
#include "windows.h"
#include "psapi.h"
#include <iostream>
#include <vector>
#include <queue>
int main (int, char* [])
{
PROCESS_MEMORY_COUNTERS pm;
GetProcessMemoryInfo(GetCurrentProcess(), &pm, sizeof(pm));
size_t mem1 = pm.WorkingSetSize;
std::vector<int> v( 10000000 );
GetProcessMemoryInfo(GetCurrentProcess(), &pm, sizeof(pm));
size_t mem2 = pm.WorkingSetSize;
std::deque<int> q( 10000000 );
GetProcessMemoryInfo(GetCurrentProcess(), &pm, sizeof(pm));
size_t mem3 = pm.WorkingSetSize;
std::cout << mem2 - mem1 << std::endl;
std::cout << mem3 - mem2 << std::endl;
return 0;
}
输出(在 32 位 Windows 系统上):
40087552
72564736
奖金问题:为什么 mem2 - mem1 不完全是 40000000?