terminate called after throwing an instance of 'std::bad_alloc' what(): St9bad_all

upadhyad's Avatar, Join Date: Jul 2008
Newbie Member
Hi everyone !!

i have an interesting problem...hope you people can help.
I am coding in C.
the code is posted below:
here is how I define my structure....
Code: ( text )
Code:

1.
struct IDnTime
2.
{
3.
vector<char *> s;
4.
vector<char *> g;
5.
struct tm theTime;
6.
struct tm *ptr;
7.
time_t t;
8.
} IDnTimeArray[50];

Next I inititalize few char variables and then point them with the pointers like thisthis I did to avoid pushing characters themselves in the vectors....now this should allow me to push the addresses of the characters or the poiters to thode characters in the vector)
Code: ( text )
Code:

1.
char Walk ='w',Bike ='b',Car ='c',UrbanPuT ='u',Rail ='r',Notdecided ='n',Activity ='a';
2.
char *walk =&Walk, *bike =&Bike, *car =&Car, *urbanPuT =&UrbanPuT, *rail =&Rail, *notdecided =&Notdecided, *activity =&Activity;

Then i try to push back like this
Code: ( text )
Code:

1.
IDnTimeArray[counter1].s.push_back(&Activity);
2.
IDnTimeArray[counter1].s.push_back(&Walk);

and so on.......76,000 character addresses in the vector 's'..and similarly for the vector g as well
Code: ( text )
Code:

1.
IDnTimeArray[counter1].g.push_back(&Activity);
2.
IDnTimeArray[counter1].g.push_back(&Walk);

the program compiles fine...gr8..then I run it ..it runs for 2 or three seconds ...gr8...then as the pushing back operation in the 's' vector of the array of the structures is completed and the g vector is started it stops .....when I run it on my computer the process it terminated here is
Code:

terminate called after throwing an instance of 'std::bad_alloc'
what(): St9bad_all
Aborted

i dont get this .....PLEASE HELPi dont get this .....PLEASE HELP

Also few may ask whether I try to fill all the 's' and 'g' vectors of the 50 structure array locations together.......
the answer is NO!...first I approach each structure array element and then i try to fill the s and g vectors of that location(whch is not allowed and the message displayed i mentioned above)...then as i finsh my desired function with these vectors I clear these vectors by
Code: ( text )
Code:

1.
IDnTimeArray[counter1].s.clear();
2.
IDnTimeArray[counter1].g.clear();

So the memory is freed......

HELP HELP
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Try using the code block for code snippets in the posts for better formating
upadhyad's Avatar, Join Date: Jul 2008
Newbie Member
is this website dead?