c++ - terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad -


in loop of program, when loop variable bin=8, have error:

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

and program stops.

here code:

ds=(smax-smin)/sn;     for(int bin=0; bin<sn; bin++){     s1=smin+(bin*ds);     s2=smin+((bin+1)*ds);     s=(s1+s2)/2;     if(s[j]<=s1+0.05 && s[j]>=s1-0.05){         e11=e1[j];         e12=e2[j];     }      if(s[j]<=s2+0.05 && s[j]>=s2-0.05){         e21=e1[j];         e22=e2[j];     } }  slop=(e22-e12)/(e21-e11); cout<<"bin="<<bin<<"\n"; n=-1/slop; b=-slop*e21+e22; b1=-n*e11+e12; b2=-n*e21+e22;  double x1=-b1/n;  double x2=-b2/n;  double x3=140;        double x4=140; double y3=(n*x3)+b2;  double y4=(n*x4)+b1; double y11=0.0; double y2=0.0; double  h[5]={x1,x2,x3,x4,x1}; double k[5]={y11,y2,y3,y4,y11}; sprintf(cha[1],"cut%d",bin);  cut[bin]=new tcutg(cha[1],5,h,k); (long64_t jentry=evsta; jentry<g; jentry++) {          if (cut[bin]->isinside(neout,nein)){         hp[bin]->fill(neout,nein);         h=-(slop*neout+b-nein)/sqrt(1+slop*slop);         np[bin]->fill(h);     } } 

std::bad_alloc thrown when request heap memory not satisfied (i.e., you're running out of memory). looks it's either coming new call or, fill() function. don't have code posted, can't certain.

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

if you're on platform gdb, run program in catch throw set, find out exception thrown.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -