[Halld-online] Boost shared_ptr for Hall D Online

Elliott Wolin wolin at jlab.org
Mon Dec 21 10:20:55 EST 2009


Hi,

The Boost shared pointer (a type of smart pointer) appears now to be 
standard on linux (I found it on my 32-bit and on my 64-bit RHEL 
machines).  I think we should seriously consider using it for the Hall D 
online.  See:

    http://www.boost.org/doc/libs/1_41_0/libs/smart_ptr/shared_ptr.htm

for details. 

My proposal would be to outlaw "bare" pointers for all but the most 
trivial tasks (and for backwards-compatibility in some cases), and use 
the shared_ptr extensively.  At some point I or someone else will give a 
report on this at the Online meeting.  This is not an urgent decision, 
of course.

Briefly, the shared_ptr class wraps a standard pointer in such a way as 
to eliminate memory leaks.  It keeps a reference count of the number of 
places the wrapped ptr is being used, and guarantees that delete() is 
called when it is not being used any more (very similar to what is done 
in Java). 

The Online is fortunate that no real code has been developed yet and we 
can adopt the shared_ptr before we start.  I think it would be a great 
idea for the offline to use it as well, but they 1) must support other 
architectures where it may not be standard yet, and 2) already have a 
large base of code.

Thanks,

-- 

				Sincerely,
					Elliott
 

================================================================================


 Those raised in a morally relative or neutral environment will hold
		    no truths to be self-evident.
				   

Elliott Wolin
Staff Physicist, Jefferson Lab
12000 Jefferson Ave
Suite 8 MS 12A1
Newport News, VA 23606
757-269-7365

================================================================================



More information about the Halld-online mailing list