File: memory

package info (click to toggle)
dds 2.9.0-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 56,576 kB
  • sloc: cpp: 17,621; ansic: 385; makefile: 27; xml: 11; sh: 7
file content (21 lines) | stat: -rw-r--r-- 683 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
--- a/src/System.cpp
+++ b/src/System.cpp
@@ -223,11 +223,13 @@ void System::GetHardware(
 #endif
 
 #ifdef __linux__
-  // The code for linux was suggested by Antony Lee.
-  FILE * fifo = popen(
-    "free -k | tail -n+3 | head -n1 | awk '{print $NF}'", "r");
-  int ignore = fscanf(fifo, "%llu", &kilobytesFree);
-  fclose(fifo);
+  // Use half of the physical memory
+  long pages = sysconf (_SC_PHYS_PAGES);
+  long pagesize = sysconf (_SC_PAGESIZE);
+  if (pages > 0 && pagesize > 0)
+    kilobytesFree = static_cast<unsigned long long>(pages * pagesize / 1024 / 2);
+  else
+    kilobytesFree = 1024 * 1024; // guess 1GB
 
   ncores = sysconf(_SC_NPROCESSORS_ONLN);
   return;