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