This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: trimming STL's memory pool


Ben wrote:

>As far as I know gcc's STL default
>allocator uses memory pool to boost
>its performance.
>
Actually, this is the case only of GCC 3.3.x, not GCC 3.4.x and 4.0.x.

> My program at some stage
>allocates a lot of small STL containers (vectors)
>and then after using them cleans them, but
>the memory is never returned to the system. It
>is not memory leak because if I allocate these
>containers again the memory usage of the process
>doesn't grow. Is there some way to force shrinking
>of STL's memory pool and returning memory to the
>system ? Sometimes your program needs a large amount
>of STL containers only for short period and bloating
>the process forewer is very annoying.
>  
>
A good question. I don't have a clear cut answer. I can tell you that
there are very good reasons *not* to return memory, i.e., you don't
really know when it's *really* safe, until the end of the process. We
battled with that quite a few times. Also, assuming your OS uses virtual
memory, bloating the *virtual* memory usage doesn't seem such a *big*
problem, frankly: basically, after a while, the unused memory pages get
swapped out and never return to physical memory. Which kind of
difficulties are you experiencing, exactly?

Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]