1

I am trying out a C/C++ program, I want to know how much memory i am using due to heap and some other data structures. So how can I find out the amount of memory used by my various data structures?

I think that malloc operator should be overridden but I am not sure about the same.
I am working on Linux and on Netbeans 7.1.

iammilind
  • 68,093
  • 33
  • 169
  • 336
Rose BEck
  • 185
  • 1
  • 1
  • 10
  • also see this [question](http://stackoverflow.com/questions/4690800/how-to-profile-memory-usage) – hamed Jul 01 '12 at 12:37
  • @hamed Thanks..+1 to ur comment. Also since I am working on netbeans...is there anyway by which netbeans may help me with...i am a complete novice at this..thats why asking..also thanks helping. This community really rocks because of people like u. – Rose BEck Jul 01 '12 at 12:41

2 Answers2

1

You can use memory profilers for c++ like Valgrind as recommended in similar questions. see this

For netbeans IDE look at this.

hamed
  • 597
  • 4
  • 15
  • Thanks again for the help...the link u provided if for netbeans 6.9 but I am working with Netbeans 7.1....can you please please provide some good link for netbeans 7.1...thanks again – Rose BEck Jul 01 '12 at 13:10
  • 2
    @RoseBEck: someone is preventing you from using a shell? Open it and run valgrind, it's by far the easiest way to do it – akappa Jul 01 '12 at 13:14
  • @akappa actually I am running a huge C++ project containing several files and folders..so I am a bit worried that will Valgrind work for my huge project...i know it works well for single files..but is it true that it works for huge project...also thanks for being kind and replying – Rose BEck Jul 01 '12 at 13:19
  • Release Notes of **7.1.2** say: _The C/C++ Profiling Tools were removed from the standard distribution of the IDE._ and I think that you should try @akappa solution. – hamed Jul 01 '12 at 13:22
  • http://stackoverflow.com/questions/9121344/netbeans-profiler-stops-working-after-50-thread-limit This guy seams to be using the netbeans 7.1 profiler...but i don't understand how? Can someone help – Rose BEck Jul 01 '12 at 13:35
  • @hamed I know this is a foolish question but does Valgrind work for large projects containing several files and folders – Rose BEck Jul 01 '12 at 13:44
  • 2
    @RoseBEck: valgrind runs executable, so it doesn't care how many files and directories your project is composed of. – akappa Jul 01 '12 at 14:17
  • @hamed The ouput on the linux terminal scrolls out fast and disappears when using ms_print...is theresome why by which I may see the entire output...before it disappears – Rose BEck Jul 01 '12 at 21:51
0

If you want to use hand-made memory profiling then you need to overload operator new and/or malloc() function. Though malloc() can be overloaded easily, but you need to use macro tricks.

Advantage of using and overloading operator new is that, it's easier, elegant and you can evaluate each type of struct/class separately.

iammilind
  • 68,093
  • 33
  • 169
  • 336