Boost logo

Boost Users :

Subject: Re: [Boost-users] Memory deallocation concerning boost::bind, boost::asio and shared_ptr
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2016-04-29 02:40:28


On 28 Apr 2016 at 12:14, Norman wrote:

> Alright, i made an example, that shows my problem:
>
> http://melpon.org/wandbox/permlink/S56tYueJySIHdsWO
>
> Vinnie_win aka. Vinnie falco told me, that I might be looking at the wrong
> indicator for my memory use. But I thought the Resident Set Size is the
> value to look for, since I want to know how much memory my program is
> currently allocating.
>
> Any help would still be really appriciated :-)

You appear to not understand how virtual memory and the system memory
allocator works and interact with one another. Please read the papers
from Denning et al from the 1970s. All major OSs use his design.

RSS is the *cache* of memory held by the system in RAM of your
process' memory. It is entirely dependent on system load, how much
caching your kernel chooses, and what the libraries your processes do
internally.

It has little relevance to "how much memory my program is currently
allocating".

The closest proxy to such a thing - which doesn't really exist on any
major OS of the past thirty years - is probably the dirtied page
count. And even there, the system memory allocator will intentionally
cache a large quantity of memory it fetches from the OS, so just
because you free() everything you malloc() doesn't mean any memory is
released to the system.

If you really, really, really want to always free everything you
malloc, use mmap() to allocate and munmap() to free, or even use
sbrk(). Note that your program will run four orders of magntitude
slower.

tl;dr; If this really bothers you, use a custom STL allocator.
Otherwise so long as dirtied pages doesn't keep rising over time,
it's not an issue and don't worry about it.

Niall

-- 
ned Productions Limited Consulting
http://www.nedproductions.biz/ 
http://ie.linkedin.com/in/nialldouglas/



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net