std::bad_alloc

Discussion in 'Meet and Greet' started by SADS, Jul 5, 2011.

  1. SADS

    SADS New Member

    Joined:
    Jul 5, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi friends,

    I wrote a code to build a matrix with specific calculations. When I'm using 3000 elements works well ... But I did a test with 150.000 (150.000 x 150.000) and I had problems.

    " terminate called after throwing an instance of 'std::bad_alloc' "


    I'm copying the code part of the problem:



    void buildMatrix(ofstream &myfileOutSubsetZ, ofstream &myfileOutSubset,ofstream &myfileOut,ofstream &myfileLog,vector<string> &vetorInd)
    {
    float **AAA = 0;
    AAA = new float *[vetorInd.size()];
    for(int i=0;i<vetorInd.size();i++)
    AAA= new float [vetorInd.size()]; // PROBLEM!
    ...
    I captured the exception:

    "St9bad_alloc".

    Can you help me please?
     

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