How to find allocated memory in linux

Good afternoon everyone

What am I trying to accomplish . I would like to implement an extension for the C ++ unit test tool to determine if memory allocates memory and does not free it. My idea was to record distribution levels or free memory levels before and after the test. If they do not match, you lose memory.

What I have tried so far: I wrote a program for reading / proc / self / stat to get the size of vm and the size of the resident set. The size of the resident set seems to me what I need, but this is clearly not the case. It changes between successive function calls without memory allocation. I believe that it returns cached memory, not what is allocated. It also changes in 4k steps, so it is too coarse to be in reality.

I can get the size of the stack by highlighting the local one and saving its address. Are there any problems with this?

Is there a way to get real free or dedicated memory on Linux?

thanks

+3
source share
5 answers

, Valgrind , , mallinfo(), , uordblks.

, - , - , , . , , , , .

+3

, . Electric Fence, , , ( , ++), Dmalloc.

, Valgrind, ( , , , , ). KDE , . ( KDE, ++- , , Valgrind KDE, - . Electric Fence )

+4

. C (4 ). , .

malloc() free(), .

Valgrind.

+2

, :: new :: delete , , .

Edit: If this is a personal DIY project, then cool down. But if its for something critical, you can always go to one of the many libraries / leak detection programs, a quick google search should be sufficient.

0
source

google-perftools can be used in your test code.

0
source

Source: https://habr.com/ru/post/1714808/


All Articles