#include <iostream>
#include <cassert>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <Windows.h>
using namespace std;
char randomLetter()
{
srand(time(0));
char rValue;
while(1)
if((rValue=(rand()/129)) > 31)
return rValue;
}
int main()
{
vector<char> meegaString;
for(int i=0; i < 10000000000; i++)
{
meegaString.push_back(randomLetter());
if(!(i%10000000))
cout<<"There are: " <<i+1<<" chars in the list"<<endl;
}
system("pause");
return 0;
}
このプログラムを実行する前の RAM 使用量は、約 2500/8000 MB でした。3200 になると、次の例外がスローされます。
リソース gormandizer.exe の 0x773c15de で未処理の例外: Microsoft C++ 例外: std::bad_alloc メモリ位置 0x0045f864..
1) 64 ビット OS で動作しているのに、このプログラムが使用可能なメモリ全体を満たしていないのはなぜですか?
2) プロセッサー (インテル Core i5) の 26% しか使用されていないのはなぜですか?