[Bioclusters] (no subject)
Aaron Darling
bioclusters@bioinformatics.org
Tue, 30 Mar 2004 15:26:04 -0600 (CST)
>
> Can anyone suggest a smarter testing program (using malloc for
> example) which can better probe the per process limit?
>
> I will give it a google...
>
Here's a little c++ code I wrote a while back to do exactly that. Give
it a minute or two and it will have allocated up to the per-process limit.
Unsure whether it's necessary for your purposes, but it touches each page
to make sure they're actually allocated.
#include <iostream>
using namespace std;
int main( void ){
char* buf;
unsigned long long size = 1024 * 1024 * 512;
unsigned long long total_allocation = 0;
string junk;
for( int i = 0;; i++ ){
if( size < 512 )
break;
try{
buf = new char[ size ];
}catch( exception& e ){
cerr << "Alloc failed, new size is: " << size / 2 << endl;
cerr << "total_alloc is: " << total_allocation << endl;
size /= 2;
continue;
}
total_allocation += size;
for( unsigned bufI = 0; bufI < size; bufI+= 512 )
buf[ bufI ] = 0xAA;
}
cerr << "Allocated " << total_allocation << " bytes\n";
cerr << "That's " << (double)total_allocation / (double)(1024 * 1024) << " MB.\n";
}