Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > auto_ptr and sink

Reply
Thread Tools

auto_ptr and sink

 
 
asit
Guest
Posts: n/a
 
      08-13-2011
auto_ptr has the attribute release(). then what is the need of sink function ??
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      08-14-2011
On 14.08.2011 00:39, asit wrote:
> auto_ptr has the attribute release(). then what is the need of sink function ??


could you translate that question to English, please


cheers,

- Alf

 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      08-14-2011
On Sun, 2011-08-14, Alf P. Steinbach wrote:
> On 14.08.2011 00:39, asit wrote:
>> auto_ptr has the attribute release(). then what is the need of sink function ??

>
> could you translate that question to English, please


I don't think the problem is the English -- it's that sink function
which I've never heard of. Asit, what and where is the sink function?

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
asit
Guest
Posts: n/a
 
      08-14-2011
Please read this

http://www.gotw.ca/publications/usin...ffectively.htm

please read "Ownership, Sources, and Sinks" section
 
Reply With Quote
 
SG
Guest
Posts: n/a
 
      08-14-2011
On 14 Aug., 11:19, asit <(E-Mail Removed)> wrote:
> Please read this
>
> http://www.gotw.ca/publications/usin...ffectively.htm
>
> please read "Ownership, Sources, and Sinks" section


So?
I still don't understand the question. source() and sink() are just
examples and not part of auto_ptr's interface whereas your question
seems to suggest you think sink is part of auto_ptr's interface.

Do you understand the concept of an "example"?

Please put a little more effort into writing questions. I'm fairly
sure that most of the comp.lang.c++ members lack mind reading
capabilities.

Cheers!
SG
 
Reply With Quote
 
asit
Guest
Posts: n/a
 
      08-14-2011
I asked this because I found certain code snippets(in application, not in example) which mostly uses Source-Sink, not release method of the auto_ptr class.

Is there any advantage of using sink() instead of release() of auto_ptr ???
 
Reply With Quote
 
Asger-P
Guest
Posts: n/a
 
      08-14-2011

Hi asit

On the: 14. of august-2011 At: 13:46 asit wrote:

> I asked this because I found certain code snippets(in application, not
> in example) which mostly uses Source-Sink, not release method of the
> auto_ptr class.
>
> Is there any advantage of using sink() instead of release() of auto_ptr
> ???


If You want to do some work to the object, that auto_ptr is pointing to,
before it gets deleted there can be, but if not sink is just a fancy
way of of calling auto_ptr::reset();

BUT.. to me it sounds like You are mixing reset and release

here is an example of the use of release:

std::auto_ptr<TBitmap> Bmp( new TBitmap() );

// do stuf that can throw

BmpVector.push_back( Bmp.get() );

Bmp.release();


Now the bitmap pointer will not get deleted when auto_ptr runs
out of scoope, because You have released auto_ptr of its ownership
of the bitmap.

If You on the other hand want to "release" the memory of the object
that is pointed to by auto_ptr You have to use auto_ptr::reset instead.

std::auto_ptr<TBitmap> Bmp( new TBitmap() );
// do stuf that can throw
Bmp.reset(); // free the memory

auto_ptr::reset do a delete on the internal object and set its
internal pointer to NULL


Best regards
Asger-P
 
Reply With Quote
 
Asger Joergensen
Guest
Posts: n/a
 
      08-14-2011
Hi asit

asit wrote:

> I asked this because I found certain code snippets(in application, not in example) which mostly uses Source-Sink, not release method of the auto_ptr class.
>
> Is there any advantage of using sink() instead of release() of auto_ptr ???


If You want to do some work to the object, that auto_ptr is pointing to,
before it gets deleted there can be, but if not sink is just a fancy
way of of calling auto_ptr::reset();

BUT.. to me it sounds like You are mixing reset and release

here is an example of the use of release:

std::auto_ptr<TBitmap> Bmp( new TBitmap() );

// do stuf that can throw

BmpVector.push_back( Bmp.get() );

Bmp.release();


Now the bitmap pointer will not get deleted when auto_ptr runs
out of scoope, because You have released auto_ptr of its ownership
of the bitmap.

If You on the other hand want to "release" the memory of the object
that is pointed to by auto_ptr You have to use auto_ptr::reset instead.

std::auto_ptr<TBitmap> Bmp( new TBitmap() );
// do stuf that can throw
Bmp.reset(); // free the memory

auto_ptr::reset do a delete on the internal object and set its
internal pointer to NULL


Best regards
Asger-P
 
Reply With Quote
 
asit
Guest
Posts: n/a
 
      08-14-2011
thank you a lot Asger-P
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
explicit auto_ptr<T>::auto_ptr(T*) ? Sousuke C++ 9 03-16-2010 11:54 AM
auto_ptr<Derived> to auto_ptr<Base> Siemel Naran C++ 2 01-11-2005 04:45 AM
Using custom sink and cookies from ASP.NET application =?Utf-8?B?b3R0bw==?= ASP .Net 1 12-21-2004 05:49 PM
auto_ptr and sink function Marcin Vorbrodt C++ 4 09-22-2003 08:42 AM
Re: auto_ptr and sink function Marcin Vorbrodt C++ 0 09-22-2003 12:39 AM



Advertisments