Alex Rivera | Logout

Memory Allocation Profiling in C++

Asked 2009-03-31T05:16:25.073
54

I am writing an application and am surprised to see its total memory usage is already too high. I want to profile the dynamic memory usage of my application: How many objects of each kind are there in the heap, and which functions created these objects? Also, how much memory is used by each of the object?

Is there a simple way to do this? I am working on both linux and windows, so tools of any of the platforms would suffice.

NOTE: I am not concerned with memory leaks here.

Edit
Report

2 Answers

3

There are several things you can do. The simplest thing is to link a debug malloc library; there are aa number of them available, depending on the details of your environment (eg, google for _malloc_dbg for Windows.)

The second choice is that you can overload new and delete in C++; it's possible to overload the basic new and delete with new functions that track memory allocation and usage.

answered 2009-03-31T05:27:40.240
1

Chapter 4.6 from Game Programming Gems Volume 8 (Safari Book preview link) details a advanced memory profiler by Ricky Lung which can show the allocation statistic in a hierarchical call-stack manner and yet support multi-threading.

answered 2010-03-17T02:28:54.387

Your Answer