[Clam-devel] style

Dirk Griffioen dirk.griffioen at barcelonamedia.org
Tue May 26 01:51:36 PDT 2009


Hi David,


> On Monday 25 May 2009 19:06:38 David García Garzón wrote:
> > On Monday 25 May 2009 18:29:40 Dirk Griffioen wrote:
> > > - please note: with the use of smartpointers, this whole line becomes
> > > obsolete as they and their resources are destructed when the vector is
> >
> > I know the implications on what we are doing now, we have a clear memory
> > management policy, following it is not difficult and spoting the bugs of
> > this kind of construction is very straight forward for us. I cannot say the
> > same of the use of smart pointers as most of the things happen behind the
> > scene.
> 
> That said, i am not trying to ban the use of smart pointers. Just that it is 
> something that must be discussed with calm. I guess that smart pointers would 
> imply some other kind of policy we should stablish and learn. How to deal 
> with circular references, where to detach pointers, when and how giving away 
> references... I see no gain on porting the whole code base to smart pointers. 
> It is a lot of work that can be used to more useful things for the project. 
> If you write new code that could be a place to introduce them but also a 
> requirement for that would be solving crossplatform distribution of the 
> dependencies (boost).


I would be very interested in learning about and helping to solve the
crossplatform issues, as I believe having (parts of) boost would be very
beneficial to clam.

Having said that, smartpointers are based on RAII ('resource aquisition
is initialization' -
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization)

This is not a policy but a strong guarantee by the language that
acquired resources will be freed: I simply cannot make a fault, by
definition (which is a nice position to be in :)

Because it is so usefull, Java/C# added the 'using' keyword even in the
presence of their garbage collector. 

Regarding references/detach etc - these issues have been solved in the
boost packages:

the 'old' smartpointer package (in development since 1999)
http://www.boost.org/doc/libs/1_39_0/libs/smart_ptr/smart_ptr.htm#Introduction

and a new one
http://www.boost.org/doc/libs/1_39_0/libs/ptr_container/doc/tutorial.html

where you can do things like:

                boost::ptr_vector<animal> vec;

	vec.push_back( new animal ); // you add it as pointer ...
	vec[0].eat();                // but get a reference back


(which looks surprisingly how clam handles memory, but with more safety
attached; see the motivation:
http://www.boost.org/doc/libs/1_39_0/libs/ptr_container/doc/ptr_container.html#motivation)

So if we can add boost as a depency, we might want to consider it for
new code ...

Dirk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20090526/cae85daf/attachment-0003.htm>


More information about the clam-devel mailing list