S
Saeed Amrollahi
Dear friends
Hi
I am working on an application to manage Tehran Securities Exchange
organization.
In this program, I try to manipulate a lot of institutional investors
(about 1,500,000). The Investors are a struct like this:
struct Investor {
int ID;
std::wstring NID;
std::wstring Name;
std::wstring RegNum;
std::wstring RegDate;
std::wstring RegProvince;
std::wstring RegCity;
std::wstring Type;
std::wstring HQAddr;
// the deblanked or squeezed info
std::wstring sq_Name;
std::wstring sq_RegNum;
std::wstring sq_RegProvince;
std::wstring sq_RegCity;
};
The investors are stored in an Access Database and I read them into
memory at the program loading time. Because, each investor is
registered in a City, I tried
to use a map container: map a city to the collection of investors:
map<wstring, vector<Investor>*> g_Investor; // map city name to the
investors located in
For the sake of efficiency, I used pointer to vector as a value of
the map.
the following code fills the map:
void InvestorSearchEngine::FillInvestors(const vector<Investor>& m)
{
try {
for (vector<Investor>::const_iterator cit = m.begin(); cit !=
m.end(); ++cit) {
if (g_Investor.find(cit->second.RegCity()) != g_Investor.end()) {
// so, there is a node with reg. place already
map<wstring, vector<Investor>*>::iterator it =
g_Investor.find(cit->second.RegCity());
it->second->push_back(cit->second);
}
else { // the registered city is new
vector<Investor>* vp = new vector<Investor>();
vp->push_back(cit->second);
g_Investor[cit->second.RegCity] = vp;
}
}
}
catch(const std::bad_alloc&)
{
wofstream LogFile("D:/log.txt", std::ios_base::app);
LogFile << "Memory exhausted ... " << L'\n';
LogFile << g_Investor.max_size() << L'\n';
LogFile.close();
}
Unfortunately, sometimes, the memory allocation is failed and the
"Memory exhauseted ..."
message was written to log file.
FYI, the max_size() function returns 119304647 as of largest possible
map.
What's wrong with my code?
I use Pentium 4 CPU 3.00 GHz, 4 GB RAM and Windows XP, Visual Studio
2008.
Please throw some light.
-- Saeed Amrollahi
Hi
I am working on an application to manage Tehran Securities Exchange
organization.
In this program, I try to manipulate a lot of institutional investors
(about 1,500,000). The Investors are a struct like this:
struct Investor {
int ID;
std::wstring NID;
std::wstring Name;
std::wstring RegNum;
std::wstring RegDate;
std::wstring RegProvince;
std::wstring RegCity;
std::wstring Type;
std::wstring HQAddr;
// the deblanked or squeezed info
std::wstring sq_Name;
std::wstring sq_RegNum;
std::wstring sq_RegProvince;
std::wstring sq_RegCity;
};
The investors are stored in an Access Database and I read them into
memory at the program loading time. Because, each investor is
registered in a City, I tried
to use a map container: map a city to the collection of investors:
map<wstring, vector<Investor>*> g_Investor; // map city name to the
investors located in
For the sake of efficiency, I used pointer to vector as a value of
the map.
the following code fills the map:
void InvestorSearchEngine::FillInvestors(const vector<Investor>& m)
{
try {
for (vector<Investor>::const_iterator cit = m.begin(); cit !=
m.end(); ++cit) {
if (g_Investor.find(cit->second.RegCity()) != g_Investor.end()) {
// so, there is a node with reg. place already
map<wstring, vector<Investor>*>::iterator it =
g_Investor.find(cit->second.RegCity());
it->second->push_back(cit->second);
}
else { // the registered city is new
vector<Investor>* vp = new vector<Investor>();
vp->push_back(cit->second);
g_Investor[cit->second.RegCity] = vp;
}
}
}
catch(const std::bad_alloc&)
{
wofstream LogFile("D:/log.txt", std::ios_base::app);
LogFile << "Memory exhausted ... " << L'\n';
LogFile << g_Investor.max_size() << L'\n';
LogFile.close();
}
Unfortunately, sometimes, the memory allocation is failed and the
"Memory exhauseted ..."
message was written to log file.
FYI, the max_size() function returns 119304647 as of largest possible
map.
What's wrong with my code?
I use Pentium 4 CPU 3.00 GHz, 4 GB RAM and Windows XP, Visual Studio
2008.
Please throw some light.
-- Saeed Amrollahi