Test-maxMem.C 555 Bytes
Newer Older
shunbo's avatar
shunbo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        cerr << "Usage: " << argv[0] << " <number of Mb per chunk>\n";
        exit(1);
    }

    int nBytes = (1024U*1024U)*atoi(argv[1]);

    char *cPtr;

    for (unsigned i=1;; i++)
    {
        cPtr = new char[nBytes];

        /*
        for (int j=0; j<nBytes; j++)
        {
            cPtr[j] = 0;
        }
        */

        cout << "allocated " << i*nBytes/(1024U*1024U) << " Mbytes" << endl;
    }

    return 0;
}