00001 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // This library is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public 00005 // License as published by the Free Software Foundation; either 00006 // version 2.1 of the License. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // Lesser General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU Lesser General Public 00014 // License along with this library; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 // 00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00018 // 00019 00020 // File : SMDS_MemoryLimit.cxx 00021 // Created : Fri Sep 21 17:16:42 2007 00022 // Author : Edward AGAPOV (eap) 00023 // Executable to find out a lower RAM limit (MB), i.e. at what size of freeRAM 00024 // reported by sysinfo, no more memory can be allocated. 00025 // This is not done inside a function of SALOME because allocated memory is not returned 00026 // to the system. (PAL16631) 00027 // 00028 #ifndef WIN32 00029 #include <sys/sysinfo.h> 00030 #endif 00031 00032 #ifdef _DEBUG_ 00033 #include <iostream> 00034 #endif 00035 00036 int main (int argc, char ** argv) 00037 { 00038 // To better understand what is going on here, consult bug [SALOME platform 0019911] 00039 #ifndef WIN32 00040 struct sysinfo si; 00041 int err = sysinfo( &si ); 00042 if ( err ) 00043 return -1; 00044 unsigned long freeRamKb = ( si.freeram * si.mem_unit ) / 1024; 00045 00046 // totat RAM size in Gb, float is in order not to have 1 instead of 1.9 00047 float totalramGb = float( si.totalram * si.mem_unit ) / 1024 / 1024 / 1024; 00048 00049 // nb Kbites to allocate at one step. Small nb leads to hung up 00050 const int stepKb = int( 5 * totalramGb ); 00051 00052 unsigned long nbSteps = freeRamKb / stepKb * 2; 00053 try { 00054 while ( nbSteps-- ) { 00055 new char[stepKb*1024]; 00056 err = sysinfo( &si ); 00057 if ( !err ) 00058 freeRamKb = ( si.freeram * si.mem_unit ) / 1024; 00059 } 00060 } catch (...) {} 00061 00062 // #ifdef _DEBUG_ 00063 // std::cout << freeRamKb / 1024 << std::endl; 00064 // #endif 00065 return freeRamKb / 1024; 00066 00067 #endif 00068 00069 return -1; 00070 }