[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to test memory allocation with new ?
From: |
Sharad Kala |
Subject: |
Re: How to test memory allocation with new ? |
Date: |
Mon, 1 Nov 2004 19:21:04 +0530 |
"Sharad Kala" <no_spam.sharadk_ind@yahoo.com> wrote in message
>
> "jjleto" <jjleto@laposte.net> wrote in message
> > > char *pp = new char[...];
> >
> > Thanks, the segmentation fault was actually for the reason you gave.
> >
> > Nevertheless, I still have an error when running this program ("give up"
> > but not a segfault)
> >
> > How do I test memory allocation with new ?
>
> I told you in my earlier reply too that new throws std::bad_alloc on
> exception. You need to wrap the new in a try-catch block (catching
> std::bad_alloc).
Something like -
try{
char *pp = new char[n];
//...
}
catch(std::bad_alloc)
{
cout << "New failed";
}
Sharad
Re: How to test memory allocation with new ?, Cosmin Calinescu, 2004/11/01
Re: How to test memory allocation with new ?, Larry I Smith, 2004/11/01