I have the following in my program
class memModel
{
struct Addrlist
{
vector<string> data;
vector<int> timestamp;
vector<string> client;
}
map<int, Addrlist> AddrMap ; //store based address and list of all accesses
}
In main() I read from a few files and store millions of entries into this stuct
int main()
{
memModel newObj ;
ifstream file1("dataStream");
ifstream file2("timeStampSteam");
ifstream file3("clientStream");
ifstream file4("addrStream") ;
string dataSTR,clientSTR;
int time = 0 ;
int addr;
for(int i=0; i<10000000/*10mil*/ ; i++)
{
getline(file1,dataSTR);
getline(file3,clientSTR);
file2 >> time ;
file4 >> hex >> addr ;
newObj.AddrMap[addr].data.push_back(dataSTR) ;
newObj.AddrMap[addr].time.push_back( time) ;
newObj.AddrMap[addr].client.push_back(clientSTR) ;
}
}
So the problem is I am running out of memory and get the std::Bad_alloc exception. This code works with smaller data sizes.
I am trying to understand where the struct and Map are being stored. Is everything going on the Stack ? The vectors are dynamically allocated right. Are those going to the heap ?
This is my first time working with large data sets so I would like to understand the concepts better. How can I change this to make sure I am using the heap and I do not run out of memory.