Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the amount of memory allocated by malloc

Tags:

c

malloc

Is there an easy way to know the total amount of memory that has been allocated by every malloc in the program? I'm suffering from a memory leak and I want to find out where it is.

like image 304
Simone Avatar asked Oct 24 '25 18:10

Simone


1 Answers

There is no way in a standard, operating system neutral, fashion.

But with GNU Glibc you have mallinfo

On Linux systems, you can learn about your virtual memory map thru the /proc/self/maps (or /proc/self/smaps which gives more details) pseudo-file. For process of pid 123 you can read /proc/123/maps

Of course, details are system specific.

To find a memory leak, use a tool like valgrind

like image 72
Basile Starynkevitch Avatar answered Oct 26 '25 07:10

Basile Starynkevitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!