$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] how to use boost::shared_ptr?
From: Didier J-P Guion Firmin (gf.didierjp_at_[hidden])
Date: 2013-02-01 12:33:58
Hello young
shared_ptr holds  pointers to dynamically allocated arrays. shared_ptr
 uses "delete ptr;"  to clean-up when the pointer is no longer
referenced/goes out of scope. Use shared_array or scoped_array, which
correctly use delete[] ptr.
On Fri, Feb 1, 2013 at 11:05 AM, young <yqin_99_at_[hidden]> wrote:
> I have a class member (boost::shared_ptr):
>
> class XYZ
> {
> private:
>     boost::shared_ptr<int> m_pBuff;
>     // other member
>     ...
> public:
>     void func(int n)
>     {
>         m_pBuff.reset(new int[n]); // or m_pBuff =
> boost::shared_ptr<int>(new int[n])
>         ...;
>     }
>     // other functions
>     ...
> }
>
> The func(n) will be called many times inside / outside the class. Can I use
> shared_ptr here like:
>     m_pBuff.reset(new int[n]);
> or
>     m_pBuff = boost::shared_ptr<int>(new int[n]);
>
> I tried both and get error said heap corruption.
>
>
>
> --
> View this message in context:
> http://boost.2283326.n4.nabble.com/how-to-use-boost-shared-ptr-tp4642120.html
> Sent from the Boost - Users mailing list archive at Nabble.com.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://listarchives.boost.org/mailman/listinfo.cgi/boost-users
>
-- Didier JP GF 15 Rue Albert Roussel 75017 Paris skype : bdidierjp