【发布时间】:2015-11-30 16:34:51
【问题描述】:
在使用libstatgrab 时,我们何时以及如何释放内存。我没有看到像sg_free 这样的函数调用,它取消分配内存对象以存储系统统计信息。例如:
sg_init(1);
sg_drop_privileges()
sg_load_stats *load_stat;
while(load_stat = sg_get_load_stats(NULL) != NULL) {
cout << load_stat->min1 << load_stat->min5 << load_stat->min15);
}
上面的while循环不断调用sg_get_load_stats函数来获取cpu负载。它是使用内部缓冲区还是每次调用时都创建一个新缓冲区?如果后者是真的,我们不应该释放对象吗?谢谢。
【问题讨论】: