X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkMemoryUsage.cxx;h=9cc75d0acce73059b2aba6a083059624e9af66d4;hb=796e989ceb46f66e41e972f7505730aca0f0f916;hp=a8be21ae478db0c76f3ff33c42d525d60c9592d1;hpb=4b107ba6fbea5265930cdd750f03a0ea6a47aba5;p=clitk.git diff --git a/common/clitkMemoryUsage.cxx b/common/clitkMemoryUsage.cxx index a8be21a..9cc75d0 100644 --- a/common/clitkMemoryUsage.cxx +++ b/common/clitkMemoryUsage.cxx @@ -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;