Memory analysis product for c
I have written down a code that should do garbage collection for c programs. The problem is that I need to run it for a large number of objects say 100 mb dynamically allocated.
Is there any tool that can help me find out the memory usage of my c code at runtime. It would be pretty helpful if I can come to know the current heap size , or the number of memory blocks allocated etc. This is to compare the performance of my code. So it should run along with my code or itself run it.
If you do know please tell a little more information regarding its own impact at run开发者_如何转开发time etc. Thanks a lot... :)
Typically you can achieve this through use of your own object allocator quite easily. When you couple it into your garbage collection library, you can ensure that all GC'd objects use this allocator, so you don't miss anything. Anything not explicitly allocated by this allocator, is not garbage collected.
Look at valgrind. It provides a variety of memory analysis tools, including leak checking and heap profiling. The runtime overhead depends on the tool you are using; the full memory checker is slow, as it instruments all memory accesses, but the memory profiler should be pretty fast.
If your C library is glibc, then the malloc_stats()
function (declared in malloc.h
) will print a summary of the current usage to standard error.
精彩评论