From fe9de42802c1ac91a1dc3087880ec6f81e2a793f Mon Sep 17 00:00:00 2001 From: evomarc Date: Tue, 30 Mar 2004 16:51:06 +0000 Subject: [PATCH] Corrected errors in the "memory management" section. Thanks to ZhangQian for pointing them out --- eo/tutorial/html/eoProgramming.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/eo/tutorial/html/eoProgramming.html b/eo/tutorial/html/eoProgramming.html index d5f90c30f..7889a499b 100644 --- a/eo/tutorial/html/eoProgramming.html +++ b/eo/tutorial/html/eoProgramming.html @@ -430,9 +430,9 @@ function. which gives something like

eoTournamentSelection<EOT>  *ptSelect = new eoTournamentSelection<EOT>(tSize); -
eoBreeder<EOT> *ptBreed = new eoBreeder<EOT>(select); +
eoBreeder<EOT> *ptBreed = new eoBreeder<EOT>(*ptSselect);
eoEasyAlgo<EOT> *ptAlgo = new eoEasyAlgo<EOT>( -..., breed, ...); +..., *ptBreed, ...);

and you can then use the dynamically allocated objects anywhere. But the trouble with such a construct is that after exiting the function where such objects are defined, you will never be able @@ -451,10 +451,10 @@ to care of.

eoTournamentSelection<EOT>  *ptSelect = new eoTournamentSelection<EOT>(tSize);
state.storeFunctor(ptSelect); -
eoBreeder<EOT> *ptBreed = new eoBreeder<EOT>(select); +
eoBreeder<EOT> *ptBreed = new eoBreeder<EOT>(*ptSelect);
state.storeFunctor(ptBreed);
eoEasyAlgo<EOT> *ptAlgo = new eoEasyAlgo<EOT>( -..., breed, ...); +..., *ptBreed, ...);

state.storeFunctor(ptAlgo);

or, even more quickly (though less readably)

eoTournamentSelection<EOT>  *ptSelect @@ -463,10 +463,10 @@ to care of. state.storeFunctor(new eoTournamentSelection<EOT>(tSize));
eoBreeder<EOT> *ptBreed =
               -state.storeFunctor(new eoBreeder<EOT>(select)); +state.storeFunctor(new eoBreeder<EOT>(*ptSelect));
eoEasyAlgo<EOT> *ptAlgo =
               -state.storeFunctor(new eoEasyAlgo<EOT>( ..., breed, ...)); +state.storeFunctor(new eoEasyAlgo<EOT>( ..., *ptBreed, ...));

In both the above code, state is an eoFunctorStore that is of course passed from outside the function - and it's called state because in most cases it will actually be an eoState.