codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Problem with deallocating hash_map.  kon at 05:19 on Monday, July 31, 2006
 

Hi there,

I am experiencing a problem with deallocation of a hash_map container. Here is the example code:


#include <functional>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <climits>
#include <ext/hash_map>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iostream>
#include <blitz/array.h>


using namespace std;
using namespace blitz;


using namespace __gnu_cxx;


typedef pair <int, int> Coordinates;
namespace __gnu_cxx
{
struct hash <Coordinates>
{
size_t operator()(const Coordinates& c) const
{
return (c.first << 24) + c.second;
}
};
}


typedef hash_map <Coordinates , double> HASH_MATRIX;


void
constructHashMatrix(HASH_MATRIX& hashMatrix,
const int& i,
const int& j,
const double& value) {
// create a pair
Coordinates ij(i,j);
// search for the pair in the table
// Coordinates i,j already exist. Locate this record and add to its current value
hash_map <Coordinates , double>::iterator pos = hashMatrix.find(ij);
if (pos == hashMatrix.end()) {
hashMatrix[ij] = value;
}
else {
pos->second += value;
}
}


int
main() {
HASH_MATRIX HM;
HASH_MATRIX::iterator p;
int n = 20000000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 100; j++) {
double value = 3.14;
constructHashMatrix(HM, i, j, value);
}
}
HM.clear();
return 0;
}

When I use HM.clear() the system releases some memory but the majority (75%) is still in use. I want to destroy the whole object and release the memory for use by another object. I would greatle appreciate your help. Thanks in advance.

Sincerely,

Kon










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime
•  help me
•  pls help me with this..
•  Re: Security - Code verify
•  Job @ EarlySail
•  Job @ EarlySail (perl)
•  IPC problem
•  Re: import contacts of msn/yahoo


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007