Please tell my errors whatever is.
Printable View
Please tell my errors whatever is.
You might use a "proper compiler".Quote:
Originally Posted by CornedBee
Kurt
Use (nothrow). Sometimes it doesn't work.
Once I included new.h and tried set_new_handler(), but it generated error. I think it was because of my old headers.
>> Sometimes it doesn't work.
>> Once I included new.h and tried set_new_handler(), but it generated error.
Vague. Really really really vague.
Use nothrow to force new not to generate exception.(Although it wont work with old headers). Another way to handle errors is to use set_new_handler() from new or new.h
Headers.
Code with new.h compiles in my PC but generates an assertion fail and doesn't work.
Clear?Code:void errh(void);
const int arlmt=10000;
long double *v[arlmt];
const int ind =10000000;
main()
{
set_new_handler(errh);
int nfaloc=0;
int sum=0;
for(int s=1;s<arlmt;s++)
{
v[s]=new long double[ind/s];
if(v[s])
{
for(int i=0;i<ind/s;i++) *(v[s]+i)=(long double)i;
sum+=(ind/s);
int fortest=0;
cout<< ((ind/s)*8)/(1024)
<<" KBs at "<< v[s]
<<" Test: ";
for(i=0;i<ind/s;i++) {
if(*(v[s]+i)!=(long double)i) {fortest=1;break;}
}
if(fortest==1) cout<<"Failed. ";
else cout<<"OK. ";
cout << "Total: "<<(sum*8)/(1024*1024)<<" MBs allocated and tested."<<endl;
}
else
nfaloc++;
}
cout<<nfaloc<<" Number of allocations failed!"<<endl;
cout<< "Press a key..." <<endl;
getch();
return 0;
}
void errh(void)
{
cout<<"ERR allocating!"<<endl;
}