do STL containers buffer nodes to pools?

M

Mark

If you have STL containers (like list, vector,...) in
functions as automatic variables, do the nodes that
are put on the containers get buffered so they can be reused
by later container operations?

For example, if I have 10 member methods, and lots of them have
a list <Foo*> when that list is cleared or goes out
of scope, the nodes are deleted (don't worry about deleting the
Foo* themselves, they are just extra pointers to classes in a
DB, in this program the list being cleared or out of scope doesn't
mean the pointers are lost and memory leaked)

But are they really deleted or does STL buffer them in a pool
somewhere so that the next method when it does

list<Foo*> mylist;
mylist.push_back(fooptr);

could just grab a node from a pool and put the fooptr in it
without newing a node? I've read that to do this buffering for
STL, you'd have to get a special allocator to do that.. implying
the default allocators you get with a compiler like Gcc don't
do buffering?


Mark
 
M

Mark

Mark said:
If you have STL containers (like list, vector,...) in
functions as automatic variables, do the nodes that
are put on the containers get buffered so they can be reused
by later container operations?

For example, if I have 10 member methods, and lots of them have
a list <Foo*> when that list is cleared or goes out
of scope, the nodes are deleted (don't worry about deleting the
Foo* themselves, they are just extra pointers to classes in a
DB, in this program the list being cleared or out of scope doesn't
mean the pointers are lost and memory leaked)

But are they really deleted or does STL buffer them in a pool somewhere
so that the next method when it does

list<Foo*> mylist;
mylist.push_back(fooptr);

could just grab a node from a pool and put the fooptr in it
without newing a node? I've read that to do this buffering for
STL, you'd have to get a special allocator to do that.. implying
the default allocators you get with a compiler like Gcc don't
do buffering?


Mark

I found a SGI url that seems to suggest that some kind of buffering
can go on, referring to the section called:

"Why does Bounds CheckerTM say that I have memory leaks?"
http://www.sgi.com/tech/stl/FAQ.html

but another thing I'm wondering is over what scope does
this work over? If I have a file1.cc and file2.cc defining
different class methods, will STL share the memory everywhere
for list operations in the program or only among containers that are
in each particular class?


Mark
 
D

David Harmon

On Thu, 14 Apr 2005 11:22:37 -0400 in comp.lang.c++, Mark
If you have STL containers (like list, vector,...) in
functions as automatic variables, do the nodes that
are put on the containers get buffered so they can be reused
by later container operations?

When the container is destroyed, all of the memory it is using is
returned to the general free memory pool. That memory can then be
reused for later container operations or any other kind of dynamic
memory allocation.
 
M

Mark

David said:
On Thu, 14 Apr 2005 11:22:37 -0400 in comp.lang.c++, Mark



When the container is destroyed, all of the memory it is using is
returned to the general free memory pool. That memory can then be
reused for later container operations or any other kind of dynamic
memory allocation.

I guess you mean the free pool of the operating system in general,
ie. delete is being called. I found some information after my post
that suggests it doesn't do that (REF: stl_alloc.h in gcc's headers
for STL) but rather buffers the objects. If you request something
bigger than 128 bytes, it malloc/news it, but if < 128 bytes it gets
it from a pool. I'm just trying to confirm that or figure out the details

Ref: last paragraph at this SGI site:
http://www.sgi.com/tech/stl/FAQ.html

Mark
 
D

David Harmon

On Thu, 14 Apr 2005 14:12:59 -0400 in comp.lang.c++, Mark
I guess you mean the free pool of the operating system in general,
ie. delete is being called.

Yes, delete is called. Memory is returned to the pool managed by the
runtime library. Most implementations will not ordinarily return any
memory to the operating system until the program ends.
I found some information after my post
that suggests it doesn't do that (REF: stl_alloc.h in gcc's headers
for STL) but rather buffers the objects.

The objects have been destroyed. I have no idea really what you mean
by "buffer" them.
 
S

Sebastian Redl

Mark said:
If you have STL containers (like list, vector,...) in
functions as automatic variables, do the nodes that
are put on the containers get buffered so they can be reused
by later container operations?

You don't know, simple as that. Memory handling of std::allocator is at the
discretion of the implementation, and it can do whatever it wants. Someone
posted a snippet from the GCC docs elsewhere that indicates it buffers, but
that means nothing.

If you want to make sure it's buffering, write your own allocator. Or find
one on the web, I'm sure there are implementations out there.
 
M

Mark

David said:
On Thu, 14 Apr 2005 14:12:59 -0400 in comp.lang.c++, Mark



Yes, delete is called. Memory is returned to the pool managed by the
runtime library. Most implementations will not ordinarily return any
memory to the operating system until the program ends.




The objects have been destroyed. I have no idea really what you mean
by "buffer" them.

By buffer I mean exactly that the memory is returned to the pool
managed by the library and not to the OS via the global delete.
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top