[Clam-devel] style

David García Garzón dgarcia at iua.upf.edu
Wed May 27 01:09:45 PDT 2009


A Dimarts, 26 de maig de 2009 10:51:36, Dirk Griffioen va escriure:
> 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.

Yes, and i was waiting for you to say that ;-) I guess that introducing boost 
into CLAM is not a priority for your employer but if besides that you end up 
doing it here are the tips:

For Windows, feeding this monster:
http://clam-project.org/wiki/Devel/Windows_MinGW_cross_compile
Optionally feeding this other one:
http://clam-project.org/wiki/Devel/Windows_MinGW_build
And updating this binary:
http://www.clam-project.org/download/win/clam-3rdparty-mingw-20080128.tar.gz
Also updating nsis scripts to install the required dll's.

Mac, feeding this monster:
http://clam-project.org/wiki/Devel/Mac_OSX_build
And updating the bundle generation to include the required dll's.

For linux, updating the INSTALL file with the new dependency.

In general some scons work must be done in:
clam/trunk/CLAM/scons/libs/clam_dependent_libs_checks.py
clam/trunk/CLAM/scons/libs/core/SConscript

I am sure that as soon as you see the Sconstruct code you will want to 
refactor it. I do. Feel free to proceed keeping an eye on the testfarm page.

> 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#Introduct
>ion
>
> 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.h
>tml#motivation)
>
> So if we can add boost as a depency, we might want to consider it for
> new code ...
>
> Dirk

I do like it for most uses of pointer's vectors. I guess that a little care 
should be taken on resizes and deletion code as they are now done.

-- 
David García Garzón
(Work) dgarcia at iua dot upf anotherdot edu
http://www.iua.upf.edu/~dgarcia





More information about the clam-devel mailing list