-
Vector and memory
I have a struct:
struct UT210
{
string sLID;
string sCID;
};
And a vector that uses the struct:
vector<UT210> vecUT210AP;
And a temp var in my function:
UT210 stUT210;
That takes in results from an sql fetch, which does a select * from the table:
Code:
while ( !g_bBottomRecord)
{
i++;
stUT210.sLID = (char*)m_Data[1];
stUT210.sCID = (char*)m_Data[0];
vecUT210AP.push_back(stUT210);
Fetch();
}
In total there are around 34,000 records to be taken in.
The problem I have is that I get an out of memory error, which I am going to guess is caused by the increasing of the vector. So am I doing something wrong here? Is there a better way to do this? Am I just putting to much data into this vector.
Oh my machine is a 3GHz HT w/ 4GB of RAM so I doubt that its my machine.
-
Hi!!
If m_Data array already has data stored in it and m_Data is not being deleted after copying the data in the vector then it is better to store the address(pointer) to respective data than to store the whole data. That may solve the memory problem
Regards
Shaunak
-
Also you should try to find out the number of rows and use vector::reserve to allocate memory in advance to speed things up.
-
Did that already and it helped alot. I was also leaking a little on the fetch which wasn't helping.