S
Steffen Krippner
Hi,
I have extracted our way to use some STL containers in the following
program:
#include <iostream>
#include <string>
#include <list>
#include <deque>
#include <set>
using namespace std;
int main(int argc, char **argv)
{
// some simple pointers
int* myInt = new int;
*myInt = 7;
int* myInt2;
// the STL containers
std::list<int*> theList;
std::multiset<int*> theSet;
for ( int i = 0; i < 5000; i++ )
{
// fill the list with a number of elements
for ( int j = 0; j < 3000; j++ )
{
theList.push_back( myInt );
}
// do some insert/remove operations on the list
// and allocate some more memory
for ( int j = 0; j < 50 + i*2; j++ )
{
theList.pop_front( );
myInt2 = new int;
*myInt2 = 9;
theSet.insert( myInt2 );
theList.push_back( myInt );
}
// free all the memory except for myInt*
while ( theSet.size() > 0 )
{
delete *(theSet.begin());
theSet.erase( theSet.begin());
}
// clear the list
theList.clear();
}
// free the last bit of memory
delete myInt;
}
This program continuosly grows in size running on Solaris 2.8 with the
Sun Workshop 6.0 CC compiler. However all allocated memory is freed-
there is no memory leakage. The Sun Workshop comes with an STL
implementation from Rogue Wave.
Can anyone explain the process growth?
If this is due to memory fragmentation- why is it fragmenting? The
program is allocating memory chunks of the same size and in the same
sequence with each run of the outmost for- loop?
Thank you for your assistance.
Steffen
I have extracted our way to use some STL containers in the following
program:
#include <iostream>
#include <string>
#include <list>
#include <deque>
#include <set>
using namespace std;
int main(int argc, char **argv)
{
// some simple pointers
int* myInt = new int;
*myInt = 7;
int* myInt2;
// the STL containers
std::list<int*> theList;
std::multiset<int*> theSet;
for ( int i = 0; i < 5000; i++ )
{
// fill the list with a number of elements
for ( int j = 0; j < 3000; j++ )
{
theList.push_back( myInt );
}
// do some insert/remove operations on the list
// and allocate some more memory
for ( int j = 0; j < 50 + i*2; j++ )
{
theList.pop_front( );
myInt2 = new int;
*myInt2 = 9;
theSet.insert( myInt2 );
theList.push_back( myInt );
}
// free all the memory except for myInt*
while ( theSet.size() > 0 )
{
delete *(theSet.begin());
theSet.erase( theSet.begin());
}
// clear the list
theList.clear();
}
// free the last bit of memory
delete myInt;
}
This program continuosly grows in size running on Solaris 2.8 with the
Sun Workshop 6.0 CC compiler. However all allocated memory is freed-
there is no memory leakage. The Sun Workshop comes with an STL
implementation from Rogue Wave.
Can anyone explain the process growth?
If this is due to memory fragmentation- why is it fragmenting? The
program is allocating memory chunks of the same size and in the same
sequence with each run of the outmost for- loop?
Thank you for your assistance.
Steffen