Re: return memory to the OS
From: bartek (spam.will.eat.itself_at_o2.pl)
Date: 08/11/04
- Next message: Siemel Naran: "Re: iterating ENUM"
- Previous message: Victor Bazarov: "Re: Keypress with virtual key. (keybd_event)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 11 Aug 2004 15:35:06 +0000 (UTC)
hungryforc@hotmail.com (~Gee) wrote in news:83c2e7de.0407121047.3a260df2
@posting.google.com:
> Hi Folks!
> Please see the program below:
>
> 1 #include<iostream>
> 2 #include<list>
> 3 #include <unistd.h>
> 4 using namespace std;
> 5 int main()
> 6 {
> 7 {
> 8 list<int> tempList;
> 9
> 10 cout << "going to start adding now ..." << endl;
> 11 for(long i=0; i<= 1000000; i++)
> 12 {
> 13 tempList.push_back(i);
> 14 }
> 15 cout << "done adding." << endl;
> 16 sleep(10);
> 17 }
> 18
> 19 cout << "out of scope" << endl;
> 20 sleep(10);
> 21 return 0;
> 22 }
>
> When I run this program with top running, I see that even after line
> 19 is printed the memory(which top returns as 16 M) is not returned to
> the operating system(Red Hat Linux 9.). I understand that this is an
> optimization by STL to cache the memory for future use, but is it
> possible to make STL return this memory to the OS (say using a system
> call)?
It looks like an obvious small object pooling artifact.
The list<int> container most allocates lots of small nodes, which are
probably around 12 bytes each. AFAIK this object size qualifies for the
small object allocator to put them into its own memory pool. Usually such
pools are never actually explicitly returned to the system, and are
reclaimed only in the act of process termination.
You could do a quick test by supplying a bigger object as an element for
the list.
E.g.
#include <iostream>
#include <list>
struct Big
{
int array[64];
};
using namespace std;
int main()
{
{
list<Big> tempList;
cout << "going to start adding now ..." << endl;
for(long i=0; i<= 1000000; i++)
{
tempList.push_back(Big());
}
cout << "done adding. press enter." << endl;
cin.get();
}
cout << "out of scope. press enter." << endl;
cin.get();
return 0;
}
Cheers.
-- :: bartekd / o2 pl :: "out of confusion comes chaos -- out of chaos comes confusion and fear :: -- then comes lunch."
- Next message: Siemel Naran: "Re: iterating ENUM"
- Previous message: Victor Bazarov: "Re: Keypress with virtual key. (keybd_event)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|