STL Associative Containers - Problems with deallocating memory
Hi,
In our software we are using Associative Containers
to store a huge amount of items in some situations.
For example at one point we are using a STL set to store
a huge amount of strings.
Memory used by this STL set is often more than 200 MB.
When the set goes out of scope, all memory used by the set gets deallocated
automatically.
Using a Memory-Tool shows that all the deallocated memory
ends up in "Reserved Memory" and not in "Free Memory".
STL map shows the same effect.
Here is some sample code:
int main()
{
{
// At this point reserved memory is 3 MB
std::set<std::string> strSet;
for (int i=0; i<2000000; i++)
{
char tmp[32];
sprintf(tmp,"ABCDEFG1%010d",i);
std::string str (tmp);
strSet.insert(str);
}
}
// At this point reserved memory is 258 MB
return 0;
}
Such huge STL Containers only needed a few times in our software.
Mostly associative containers with moderate sizes are needed.
The problem is:
At this point there are several hundred MB of memory
reserved by the system for future use (with associative containers?).
The reserved memory is not available for other operations.
Is there a way to deallocate the memory
,used by a Associative Container,
so that memory is given completely back
to the "Free Memory" ?
Thanks for any help!