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

Discussion in 'C' started by upadhyad, Jul 10, 2008.

  1. upadhyad

    upadhyad New Member

    Joined:
    Jul 10, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Try using the code block for code snippets in the posts for better formating
     
  3. upadhyad

    upadhyad New Member

    Joined:
    Jul 10, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    is this website dead?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice