View Single Post

   
  #1 (permalink)  
Old 01-05-2008, 07:59 AM
Digital Puer
 
Posts: n/a
Default Running out of memory at under 2GB

I'm running into a problem where my program is running out
of memory at under 2GB, but lsattr says my realmem is 8GB.

I have compiled with xlC -q64 and different -bmaxdata values,
but to no avail.

Below is a simple program that uses an STL vector and
pushes random unsigned long long integers (8 bytes).
It fails at counter=136216567, meaning that it runs out of
memory at 136216567*8=1089732536 bytes = 1GB (and I
assume the next vector reallocation will push the vector
past 2GB).


Can someone suggest what I can do? I would like to be able
to use up as much of my system's 8GB as possible.


Compile:
xlC -bmaxdata:0x80000000 -O5 -qunroll -q64 memorytest.C


#include <stdio.h>
#include <vector>
#include <string.h>
#include <time.h>
#include <stdlib.h> /* random, srandom */

using namespace std;

vector<unsigned long long> v;

main()
{
unsigned long long value;
int counter;
srandom(time(NULL));

for (counter = 0; counter < 500000000; counter++)
{
value = ((unsigned long long)random() << 32) | (unsigned
long)random();
try
{
v.push_back(value);
}
catch(bad_alloc ex)
{
perror("problem: ");
printf("push_back failed: %s\n", ex.what());
printf("counter = %d\n", counter);
printf("vector capacity: %d\n", v.capacity());
exit(1);
}
if ((counter % 2000000) == 0) printf("%d\n", counter);
}


}





The end result is:
problem: : Not enough space
push_back failed: bad allocation
counter = 136216567
vector capacity: 136216567

Reply With Quote