Hi Ulrich, If you get a C pointer from a ref_ptr<> you are explicitly moving outside the scope of automatic reference counting. It's only safe to get and use a C pointer from a ref_ptr<> if you know the object being referenced will not get unreferenced during the lifetime of the C pointer. If you don't feel comfortable with this responsibility then simply don't get a C pointer, just pass around ref_ptr<>'s, the availability of get() method is to allow power users to use the speed and flexibility of the C pointer when they know it's safe.
Robert. On 5 March 2014 21:00, Ulrich Hertlein <[email protected]> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > Hi guys, > > during a recent discussion at the office the question was raised whether > or not there's > anything architectural that's stopping the owner of a ref-counted resource > to return it > via a raw pointer and dereference (and hence delete it) before it's > assigned to a > receiving ref_ptr. > > Along these lines: > caller: Resource* r = foo(); > owner: return m_resource.get() > (separate thread does m_resource.reset() or similar) > caller: ref_ptr p(r); > > ref_ptr is assigned return value of 'foo()' which is now a dangling > pointer. > (Yes, you would usually do 'ref_ptr p(foo())' but that's not fundamentally > different > from the above sequence.) > > To the best of my knowledge there's nothing in the design of ref_ptr that > stops this, > but then again I don't believe it's an issue because otherwise we'd surely > have heard. > > Can anyone think of something (in the ABI, or elsewhere) that would > prevent this? > > Cheers, > /ulrich > > - -- > Fingerprint 0227 8EE1 2C64 8EF4 DA11 9864 FF16 0114 B9DA 3318 > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1 > > iQEcBAEBCAAGBQJTF5BRAAoJEP8WARS52jMYaHcH/igaGEoeexD1kdO2c3KNER/N > VCeLvswEvoWqTV6Q9legodZgGUgeAXClx8p+lZcM8uizTLy5LknDkRn87It58vF8 > cJfZLcgbwuw/8BA3qF/iURn8taAgqBYM97t1tWPuLnoshnW1WU0C6G5Q8uJuWRUR > TfqVxCvcllXLOZPefOeS3cLI4YUgxIRywUGNTW5A+4/vNa2kJAvVr1ZDnuT8/fjg > vpYiV761iR+TM/bKPTS1+wsC723iYFSYl/7WL1Sgy/NevB/BUz9H75wtkyCXib3J > APlweXbYZF2RH20Mu/3hO59SLrOZ8wefEOtc2fXjNn2URAfzVmr9mPRtphJTCUE= > =YK8M > -----END PGP SIGNATURE----- > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

