George
Wed Jan 09 21:35:01 CST 2008
Hi Alexander,
Why it is not good that it could grow?
regards,
George
"Alexander Nickolov" wrote:
> std::vector is not the proper replacement for an array since it
> can grow. The correct class would be one of:
> boost::scoped_array<>
> boost::shared_array<>
>
>
http://www.boost.org
>
> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD
> email: agnickolov@mvps.org
> MVP VC FAQ:
http://vcfaq.mvps.org
> =====================================
>
> "Giovanni Dicanio" <giovanni.dicanio@invalid.com> wrote in message
> news:O1YehCWUIHA.4752@TK2MSFTNGP05.phx.gbl...
> >
> > "George" <George@discussions.microsoft.com> ha scritto nel messaggio
> > news:4BB7949B-C074-4310-A872-C5CFC96F2809@microsoft.com...
> >
> >> Should I delete memory pointed by pointer a if there is bad_alloc when
> >> allocating memory in memory pointed by pointer b? I am not sure whether
> >> there
> >> will be memory leak if I do not delete a.
> >>
> >> [Code]
> >> try {
> >> a = new int [N];
> >> b = new int [M];
> >
> > David W. and others suggested RAII and exception-safe std::vector usage. I
> > completely agree with them.
> >
> > I'd just like to add that:
> >
> >> } catch (bad_alloc)
> >
> > I think you should catch using *reference*, e.g.:
> >
> > } catch( std::bad_alloc & )
> >
> > Giovanni
> >
> >
> >
>
>
>