Board index » cppbuilder » Re: freeing memory from a 2d map???

Re: freeing memory from a 2d map???


2003-09-11 10:01:41 PM
cppbuilder36
JD wrote:
Quote
"Jason W. Hinson" < XXXX@XXXXX.COM >wrote:
>[...] This basic problem is killing my memory usage and
>causing me big trouble!

Try using the clear() method prior to the map going out of scope.
Thanks for the reply!
The code below shows what I've tried, and all three buttons produce the
same result--every time you click any of buttons, memory usage increases
even though each time the 2d map goes out of scope and should thus give
memory back to the app. The "clear" method doesn't seem to do anything
to help here!
I'm really stuck. Can anyone else try this and see if they can get a 2d
map to properly give back memory to the app???
typedef std::map<int,float>MapToFloat;
typedef std::map<int,MapToFloat>MapToFloat2D;
void __fastcall TForm1::Button6Click(TObject *Sender)
{
MapToFloat2D TmpMap;
for (int i=0 ; i<10 ;i++) {
for (int j=0 ; j<10000 ; j++) {
(TmpMap[i])[j] = 0.0;
}
}
Panel4->Caption = "Size Of Map: " + (AnsiString)TmpMap.size();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
MapToFloat2D TmpMap;
for (int i=0 ; i<10 ;i++) {
for (int j=0 ; j<10000 ; j++) {
(TmpMap[i])[j] = 0.0;
}
}
Panel4->Caption = "Size Of Map: " + (AnsiString)TmpMap.size();
TmpMap.clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button8Click(TObject *Sender)
{
MapToFloat2D TmpMap;
for (int i=0 ; i<10 ;i++) {
for (int j=0 ; j<10000 ; j++) {
(TmpMap[i])[j] = 0.0;
}
}
Panel4->Caption = "Size Of Map: " + (AnsiString)TmpMap.size();
for (int i=0 ; i<10 ;i++) {
TmpMap[i].clear();
}
TmpMap.clear();
}
Thanks.
-Jason
 
 

Re:Re: freeing memory from a 2d map???

Jason W. Hinson wrote:
Quote
I'm really stuck. Can anyone else try this and see if they can get a 2d
map to properly give back memory to the app???
Tried it, but bcb5 won't compile:
Quote
typedef std::map<int,float>MapToFloat;
[C++ Error] Unit1.cpp(18): E2316 'map' is not a member of 'std'
Is memory given back at program termination ?
What does codeguard report ?
Hans.