Boost logo

Boost Users :

Subject: Re: [Boost-users] question about boost pointer
From: Brian Budge (brian.budge_at_[hidden])
Date: 2012-06-09 11:53:40


On Sat, Jun 9, 2012 at 8:16 AM, Ted Byers <r.ted.byers_at_[hidden]> wrote:
>> -----Original Message-----
>> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
>> bounces_at_[hidden]] On Behalf Of young
>> Sent: June-09-12 10:34 AM
>> To: boost-users_at_[hidden]
>> Subject: Re: [Boost-users] question about boost pointer
>>
>> example:
>>
>> class MyClass
>> {
>>     boost::shared_ptr<boost::shared_array&lt;char>> pBuff;
>>
>>     void getnextpacket(size)
>>     {
>>         pBuff = boost::shared_ptr<boost::shared_array&lt;char>> (new
>> boost::shared_array<char>(new char[size]));
>>         ...
>>     }
>>
> Why bother with boost::shared_ptr here?  It adds nothing of value to the mix
> that I can see.
>
> Why not try something like:
>
> class MyClass {
>  private:
>    boost:shared_array<char> pBuff;
>  public:
>    void getNextPacket(size) {
>      pBuff.reset(new char[size]);
>      ....
>    }
>    ...
> }
>
> Cheers
>
> Ted
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

There's also the question of why you need a shared_ptr or shared_array
here at all. Will the array be passed around where you can't easily
scope the lifetime of the data?

  Brian


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