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

Hi All
i am coding with c in linux, i have this part of my code:


TApplication fooApp("fooApp",&argc,argv);
TH2F *h1 = new TH2F("2dim","two-dimensional histogram",100000,0,100000,8191,0,8191);

TCanvas *c1 = new TCanvas("c1","New Canvas 1",200,10,600,600);
c1->Divide(1,1);


if((data[36]==0)&&(data[37]==0)&&(data[38]==0)&&(data[39]==0)&&(data[40]==0)&&(data[41]==1)&&(data[42]==0)&&(data[43]==1))
{
M=0;
for(a=0;a<12;a++)
M=M+(data[a]*power(2,a));
h1->Fill(H[0],M,1);
}



c1->cd(1);
h1->Draw();

fooApp.Run();


(data is a string that contains binary numbers and H[0] is a number )

when i try to compile this code it shows me this error:
terminate called after throwing an instance of 'std::bad_alloc'
what(): St9bad_alloc

the funny thing is that when i make (a) in this loop:
for(a=0;a<12;a++)
M=M+(data[a]*power(2,a));

runs till 10 and not 12 the code works fine without errors.
any idea why is that happening, and how can i fix that????
Without digging too deeply, it looks like you've run out of memory.

See http://www.cplusplus.com/reference/std/new/bad_alloc/

You say this error happens while you're compiling the code. Perhaps there is a newer version of the compiler available?

Or perhaps try shrinking the size of the objects you are attempting to allocate memory for.
thanks for answerring me, i will try to shrink the size of the objects
1
2
TH2F *h1 = new TH2F("2dim","two-dimensional histogram",100000,0,100000,8191,0,8191);
TCanvas *c1 = new TCanvas("c1","New Canvas 1",200,10,600,600);
This ain't java. That is problably a leak, instead use
1
2
TH2F h1("2dim","two-dimensional histogram",100000,0,100000,8191,0,8191);
TCanvas c1("c1","New Canvas 1",200,10,600,600);
Topic archived. No new replies allowed.