简体   繁体   English

你如何评估内存消耗?

[英]How do you benchmark memory consumption?

I would like to know if there is an efficient way to measure the actual memory consumption of a particular C data structure. 我想知道是否有一种有效的方法来测量特定C数据结构的实际内存消耗。

The goal being to make benchmarks based on how the memory usage changes after specific operations on those data structures. 目标是根据在对这些数据结构进行特定操作后内存使用情况如何变化来制定基准。

I do not seek a way to count the number of objects in use; 我不寻求一种方法来计算使用中的物体数量; I do want to know exactly how big the memory usage of an object put under stress can get. 我确实想知道在压力下对象的内存使用量究竟有多大。

Is there a standard way to do that, either in C code, or from outside? 有没有一种标准的方法可以做到这一点,无论是在C代码中,还是从外部? (Some equivalent to the time (1) utility would be a start). (某些等效于time (1)的实用程序将是一个开始)。

Obviously, I could track down every single pointer and do a sum of all sizeof s. 显然,我可以追踪每个指针,并对所有sizeof进行求和。 If this is the only way, please do tell me. 如果这是唯一的方法,请告诉我。 I wonder whether there is a simpler way. 我想知道是否有一种更简单的方法。 Or maybe a library to do it for me. 或者也许是一个图书馆为我做这件事。

如果要在全局级别监视程序的内存使用情况,可以使用自己的函数替换C ++中的new/delete或C中的malloc/free ,并记录内存使用情况。

在Unix上用于内存消耗你可以使用valgrind和工具Massif(+任何可视化工具),但我不知道它是否适合你的问题,因为它会给你一个详细的程序内存消耗的视图。

Yep, cnicutar, on Linux you have pmap or maybe even pstat. 是的,cnicutar,在Linux上你有pmap甚至可能是pstat。

On MS there are myriad profiling tools for VStudio depending on your contribution to the MS machine (even free ones for cmd line use). 在MS上,有许多适用于VStudio的分析工具,具体取决于您对MS机器的贡献(即使是使用cmd线路的免费分析工具)。 Call me a green horn, I don't have issues with memory leaks. 叫我绿角,我没有内存泄漏的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM