Thread: weak pointers and use_count smart pointers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446

    weak pointers and use_count smart pointers

    I've been reading about smart pointer comparison operators.
    http://www.open-std.org/jtc1/sc22/wg...004/n1590.html

    Namely, I was interested in understanding why the == operator is not defined for weak pointers. The link above taught me that not even for shared pointers is the == operator safe.

    A few doubts arised reading the above article. I would need your help understanding them:

    . What is meant by two shared pointers sharing ownership but pointing to different subobjects? How can this be?

    . what is meant by two shared pointers that have a custom deleter that doesn't delete? Is this a reference to bad code?

    . What is the address of weak pointers control block?

    Finally, not so related, I still have a little trouble understanding the advantage of weak pointers. I understand they don't increment the use count of the shared pointer they point to, however this comes at the expense of ending to manually manage my weak pointers when the shared pointer is deleted. Also, since they don't implement the == operator, i'm left with few choices at to the type of container I can use them in; sets and maps.
    Last edited by Mario F.; 07-29-2006 at 07:54 AM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed