开发者

How do you benchmark memory consumption?

开发者 https://www.devze.com 2023-03-30 04:34 出处:网络
I would like to know if there is an efficient way to measure the actual memory consumption of a particular C data structure开发者_StackOverflow.

I would like to know if there is an efficient way to measure the actual memory consumption of a particular C data structure开发者_StackOverflow.

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? (Some equivalent to the time (1) utility would be a start).

Obviously, I could track down every single pointer and do a sum of all sizeofs. 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.


If you want to monitor the memory usage of the program on a global level you can replace new/delete in C++ or malloc/free in C with your own functions and log the memory usage.


On Unix for memory consumption you can use valgrind with the tool Massif (+ any visualization tool), but I don't know if it is suited for your problem since it will give you a detailled view of all the memory consumption of your program.


Yep, cnicutar, on Linux you have pmap or maybe even 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). Call me a green horn, I don't have issues with memory leaks.

0

精彩评论

暂无评论...
验证码 换一张
取 消