From: Matt L. <mat...@gm...> - 2008-03-07 19:30:05
|
VXL maintainers, At the last VXL teleconference in January I volunteered to look into Boost smart pointers and how they could be imported into vcl. I have to admit that I haven't had time to investigate how or if they should be incorporated into VXL, but I did spend some time reading about the Boost Smart Pointer library. So here is a quick synopsis of points that are relevant to the last discussion on this topic: 1) Boost has several different smart pointers: scoped_ptr, shared_ptr, weak_ptr, intrusive_ptr, and some version of these for arrays. In summary: a) scoped_ptr is a very basic, single owner pointer (e.g. for use in pimpl), not very relevant to this discussion b) shared_ptr is a sharing pointer that does not require the object to keep it's own reference count. There is no need for a ref_count base class as used with the vbl_smart_pointer (e.g. shared_ptr<int> is perfectly valid) c) weak_ptr is the dumb pointer counterpart to shared_ptr to break cycles. You can't use raw pointers for this because the ref count is not kept in the object. d) intrusive_ptr is very similar to vbl_smart_pointer in concept. 2) I've noticed that in vbl we have vbl_scoped_ptr and vbl_shared_ptr. As far as I can tell, these are not based on the Boost code (unless maybe an old version of it), but may have similar function. 3) We decided that we only want to import parts of Boost that are in C++0x TR1 (i.e. set to be part of the next C++ standard). The only Boost smart pointers I see in TR1 are shared_ptr and weak_ptr. 4) Thread safety: "shared_ptr objects offer the same level of thread safety as built-in types." I assume this applies to weak_ptr too. 5) These pointers seems to be exception safe, but I'm not all that familiar with exceptions so maybe someone else can verify this. It seems like bringing shared_ptr and weak_ptr into vcl is good plan. I think most smart pointer use in VXL can be transitioned over time to use these classes. I think the easy of used of shared_ptr and thread safety outweigh the slight performance hit over an intrusive pointer, but we can always keep vbl_smart_pointer around for the cases where this is important. If I can find some time, and no one objects, I will try to bring these two classes into vcl. I may need some guidance since I have never touched vcl internals before. We are still sticking to the vcl_ prefix correct? So these would be vcl_shared_ptr and vcl_weak_ptr? --Matt On Fri, Mar 7, 2008 at 12:33 PM, Nicolas Burrus <nic...@en...> wrote: > mundy@le... wrote: > > I do wonder about adopting boost smart pointers vs. the existing vxl > > smart pointer. Is there a big advantage to Boost's smart pointer? > > I've just noticed an important difference between them: Boost smart > pointers are thread-safe. They implement a very efficient locking > mechanism that ensures thread-safe reference counting. This is > unfortunately not the case in vxl :-( > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Vxl-maintainers mailing list > Vxl...@li... > https://lists.sourceforge.net/lists/listinfo/vxl-maintainers > |