]> Creatis software - clitk.git/blobdiff - common/clitkMemoryUsage.cxx
Comment snoutID
[clitk.git] / common / clitkMemoryUsage.cxx
index a8be21ae478db0c76f3ff33c42d525d60c9592d1..9cc75d0acce73059b2aba6a083059624e9af66d4 100644 (file)
@@ -42,14 +42,24 @@ double clitk::GetMemoryUsageInMb()
 {
 #if CLITK_MEMORY_INFO == 1
   //sleep(1); // wait to refresh memory ? need to let the system refresh the mem
-  size_t * entries = new size_t;
-  sg_process_stats * stat = new sg_process_stats;
+  size_t entries;
+  sg_process_stats *stat;
   int i=0;
-  stat = sg_get_process_stats(entries);
+  sg_init(1);
+
+  stat = sg_get_process_stats(&entries);
+  if(stat == NULL)
+    return 0.0;
+
   // Search the current pid in the list of processes
-  while (stat[i].pid != getpid()) i++;
+  while (stat->pid != getpid() && i < entries)
+  {
+    ++i;
+    ++stat;
+  }
+
   // Display total memory size
-  double mem = stat[i].proc_resident/1000/1000; // in MB
+  double mem = stat->proc_resident/1000/1000; // in MB
   return mem;
 #else
   return 0.0;