# Compilation options
option(CLITK_EXPERIMENTAL "Enable experimental software and features" OFF)
mark_as_advanced(CLITK_EXPERIMENTAL)
-option(CLITK_MEMORY_INFO "Enable memory info (need libstatgrab)" OFF)
+option(CLITK_MEMORY_INFO "Enable memory info (need libstatgrab >= v.0.90)" OFF)
mark_as_advanced(CLITK_MEMORY_INFO)
option(CLITK_BUILD_TOOLS "Build command-line tools" OFF)
option(CLITK_BUILD_SEGMENTATION "Build command-line segmentation tools" OFF)
{
#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;