Boost logo

Boost Users :

From: Mike Marchywka (marchywka_at_[hidden])
Date: 2007-10-16 15:56:53


>reseting shared_ptr with an array from the stack is not defined? Or it
>is defined and shared_ptr can figure out it is from the stack and do
>not delete it?

Try to pass "a" to a boost::shared_ptr<int> that isn't on the stack and
try it :)
You may just be lucky this gets popped while "a" is still there.
Is that your question?

>From: "Peng Yu" <pengyu.ut_at_[hidden]>
>Reply-To: boost-users_at_[hidden]
>To: boost-users_at_[hidden]
>Subject: Re: [Boost-users] What would happen if boost::shared_ptr is
>resetto an address in the stack
>Date: Tue, 16 Oct 2007 14:26:33 -0500
>
>On 10/16/07, David Abrahams <dave_at_[hidden]> wrote:
> >
> > on Tue Oct 16 2007, "Peng Yu" <pengyu.ut-AT-gmail.com> wrote:
> >
> > > Hi,
> > >
> > > The following program runs well in my system. However, if I change 1
> > > to 0, it will terminate at the line with "delete". Does this mean that
> > > boost::shared_ptr can tell if the pointer is from the stack or the
> > > heap and does different things based on where the pointer is from?
> >
> > No. The termination is just an expression of the fact that you invoked
> > undefined behavior by passing an illegal argument to delete.
> >
> > >
> > > Thanks,
> > > Peng
> > >
> > > #include <iostream>
> > > #include <boost/shared_ptr.hpp>
> > >
> > > int main() {
> > > #if 1//try change this to 0
> > > int a[100];
> > > boost::shared_ptr<int> p(a);
> > > std::cout << std::endl;
> > > #else
> > > int a[100];
> > > delete a; // would terminate here
> > > std::cout << std::endl;
> > > #endif
> > > }
>
>I don't think my question was completely answered. Do you means
>reseting shared_ptr with an array from the stack is not defined? Or it
>is defined and shared_ptr can figure out it is from the stack and do
>not delete it?
>
>Thanks,
>Peng
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users

_________________________________________________________________
Get a FREE Web site and more from Microsoft Office Live Small Business!
http://clk.atdmt.com/MRT/go/aub0930004958mrt/direct/01/


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net