1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMDS_MemoryLimit.cxx
21 // Created : Fri Sep 21 17:16:42 2007
22 // Author : Edward AGAPOV (eap)
23 // Executable to find out a lower RAM limit (MB), i.e. at what size of freeRAM
24 // reported by sysinfo, no more memory can be allocated.
25 // This is not done inside a function of SALOME because allocated memory is not returned
26 // to the system. (PAL16631)
29 #include <sys/sysinfo.h>
36 int main (int argc, char ** argv)
38 // To better understand what is going on here, consult bug [SALOME platform 0019911]
41 int err = sysinfo( &si );
44 unsigned long freeRamKb = ( si.freeram * si.mem_unit ) / 1024;
46 // totat RAM size in Gb, float is in order not to have 1 instead of 1.9
47 float totalramGb = float( si.totalram * si.mem_unit ) / 1024 / 1024 / 1024;
49 // nb Kbites to allocate at one step. Small nb leads to hung up
50 const int stepKb = int( 5 * totalramGb );
52 unsigned long nbSteps = freeRamKb / stepKb * 2;
55 new char[stepKb*1024];
58 freeRamKb = ( si.freeram * si.mem_unit ) / 1024;
63 // std::cout << freeRamKb / 1024 << std::endl;
65 return freeRamKb / 1024;