Salome HOME
PAL16631 (SALOME crash after a mesh computation failed due to lack of memory)
[modules/smesh.git] / src / SMDS / SMDS_MemoryLimit.cxx
1 // File      : SMDS_MemoryLimit.cxx
2 // Created   : Fri Sep 21 17:16:42 2007
3 // Author    : Edward AGAPOV (eap)
4
5 // Executable to find out a lower RAM limit (MB), i.e. at what size of freeRAM
6 // reported by sysinfo, no more memory can be allocated.
7 // This is not done inside a function of SALOME because allocated memory is not returned
8 // to the system
9
10 #ifndef WIN32
11 #include <sys/sysinfo.h>
12 #endif
13
14 #ifdef _DEBUG_
15 #include <iostream>
16 #endif
17
18 int main (int argc, char ** argv) {
19 #ifndef WIN32
20   struct sysinfo si;
21   int err = sysinfo( &si );
22   if ( err )
23     return -1;
24   unsigned long freeRamKb = ( si.freeram  * si.mem_unit ) / 1024;
25
26   const unsigned long stepKb = 8; // less nb leads to hung up on Mandriva2006 without swap
27   // (other platforms not tested w/o swap) 
28
29   unsigned long nbSteps = freeRamKb / stepKb * 2;
30   try {
31     while ( nbSteps-- ) {
32       new char[stepKb*1024];
33       err = sysinfo( &si );
34       if ( !err )
35         freeRamKb = ( si.freeram  * si.mem_unit ) / 1024;
36     }
37   } catch (...) {}
38
39 // #ifdef _DEBUG_
40 //   std::cout << freeRamKb / 1024 << std::endl;
41 // #endif
42   return freeRamKb / 1024;
43
44 #endif
45
46   return -1;
47 }