auto_ptr and sink

Discussion in 'C++' started by asit, Aug 13, 2011.

  1. asit

    asit Guest

    auto_ptr has the attribute release(). then what is the need of sink function ??
     
    asit, Aug 13, 2011
    #1
    1. Advertising

  2. 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
     
    Alf P. Steinbach, Aug 14, 2011
    #2
    1. Advertising

  3. asit

    Jorgen Grahn Guest

    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 .
     
    Jorgen Grahn, Aug 14, 2011
    #3
  4. asit

    asit Guest

    asit, Aug 14, 2011
    #4
  5. asit

    SG Guest

    On 14 Aug., 11:19, asit <> wrote:
    > Please read this
    >
    > http://www.gotw.ca/publications/using_auto_ptr_effectively.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
     
    SG, Aug 14, 2011
    #5
  6. asit

    asit Guest

    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 ???
     
    asit, Aug 14, 2011
    #6
  7. asit

    Asger-P Guest

    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
     
    Asger-P, Aug 14, 2011
    #7
  8. 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
     
    Asger Joergensen, Aug 14, 2011
    #8
  9. asit

    asit Guest

    thank you a lot Asger-P
     
    asit, Aug 14, 2011
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?b3R0bw==?=

    Using custom sink and cookies from ASP.NET application

    =?Utf-8?B?b3R0bw==?=, Dec 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    464
    Scott Allen
    Dec 21, 2004
  2. Marcin Vorbrodt

    Re: auto_ptr and sink function

    Marcin Vorbrodt, Sep 22, 2003, in forum: C++
    Replies:
    0
    Views:
    451
    Marcin Vorbrodt
    Sep 22, 2003
  3. Marcin Vorbrodt

    auto_ptr and sink function

    Marcin Vorbrodt, Sep 22, 2003, in forum: C++
    Replies:
    4
    Views:
    475
    tom_usenet
    Sep 22, 2003
  4. Siemel Naran

    auto_ptr<Derived> to auto_ptr<Base>

    Siemel Naran, Jan 10, 2005, in forum: C++
    Replies:
    2
    Views:
    1,566
    Dave Rahardja
    Jan 11, 2005
  5. Sousuke
    Replies:
    9
    Views:
    1,163
    Bart van Ingen Schenau
    Mar 16, 2010
Loading...

Share This Page