Dirk Reiners wrote: > Hi Marcus, > > Marcus Lindblom wrote: > >>> Hm, I will have to defer the actual answer to Gerrit. I'll just keep >>> this situation in mind for the CPtr part, and it's definitely a problem >>> with boost::shared_ptr (which doesn't support this operation either). >>> >> My 0.02€: Boost::shared_ptr has a number of drawbacks because it >> supports non-intrusive refcount, which is required in may occations but >> for frameworks like OpenSG (and my app) it's IMO mostly a hassle. We're >> using intrusive_ptr and a very simple RefObject base class to handle >> this for our own classes. >> > But... > >> (However, the weak_ptr support of boost::shared_ptr is nice and more >> easily supported with external refcounting) >> > Yup. So my current thinking is that I'll have to write a > boost::intrusive_shared_ptr/intrusive_weak_ptr to get the best of both > worlds, > as I really can't see how to guarantee that you never need to go shared to *. > :( > Yeah, I've implemented my own weak-ptr handling as well. It's not extensively used hence not very efficient/tested. (every refobject has a std::vector<weak_ptr> and on destruction, it sets the weak_ptrs to zero, which isn't very thread-safe. It's is efficient for weak_ptr lookup, since a valid weak_ptr is guaranteed to be correct. I have some control over ref-handling in my threads, so I can manage this currently.) You could do it with an external object that is ref-counted by weak_ptrs and the refobject, and has a flag and/or back-ptr to the ref-object telling wheter it's still live or not, to avoid storing pointers-to-weak-pointers as I do. (I've probably lost you now, right?) :)
What is needed is a way to go from * to shared, you mean? Well, to do that you need to find the ref-count & deletor-storage for a certain ptr. With intrusive counting it's trivial, because it lies in the pointed to object. With non-intrusive mapping, you need a map somewhere. You could simply store a set of shared_ptr's and do a lookup there. That's what you're doing for FCPtr's anyway, no? (It'd be a bit awkward and not very efficient at all though to do that every time) However, boost::shared_ptr is quite slow compared to c-ptrs or intrusive_ptrs. I've done some measurements and it's quite horrible. It does matter in a few places if you use these pointers alot (stl-containers etc), due to cache trashing when accessing the ref-count value. Cheers /Marcus ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Opensg-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opensg-users
