[galib] dynamic_cast problem in GAList

Michael Gratton mike at vee.net
Thu Feb 28 00:43:44 EST 2008


Hi there,

I'm using galib for a research project, and I'm running into problems
with dynamic_cast in GAList. For example, GAList<T>::copy looks
something like this:

template <class T> void
GAList<T>::copy(const GAList<T> & orig)
{
  ...
  hd = _GAListCopy(DYN_CAST(GANode<T>*, orig.hd), 
		   DYN_CAST(GANode<T>*, orig.hd));
  ...
  sz = orig.sz;
}

The first interesting line of the method is setting a NULL value for
`this.hd' as both dynamic_casts return NULL, _GAListCopy checks for null
parameters and if found itself returns NULL. Thus I end up with a list
that looks like it contains nodes (`sz' still gets set successfully),
but does not. This obviously causes some problems.

According to gdb/ddd, both `this' and `orig' are instances of
GAListGenome<unsigned char>, and `orig.hd' is an instance of
GANode<unsigned char>, so I have no idea why this is breaking.

The method above is getting called in a crossover function that looks
just like GAListGenome::OnePointCrossover:

const GAListGenome<unsigned char> &mom =
  dynamic_cast<const GAListGenome<unsigned char> &>(p1);
...
GAListGenome<unsigned char> &sis=
  dynamic_cast<GAListGenome<unsigned char> &>(*c1);
sis.GAList<unsigned char>::copy(mom);

I'm trying to get galib evaluating individuals in parallel as that is
the largest part of the execution time for the process. The parallel
code is based on the pvmind example code provided in the galib
distribution.

The weird thing is that the sequential version of this runs fine, but
the parallel version does not. The sequential version shares the same
code base as the parallel master process except the latter sets a custom
population initialiser and evaluator.

Does anyone have any suggestions as to why dynamic_cast refuses to play
ball?

Thanks,
/Mike

-- 
✌ Michael Gratton. Geeknik since 1976.
✇ <http://web.vee.net/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mailman.mit.edu/pipermail/galib/attachments/20080228/380c8af0/attachment.bin


More information about the galib mailing list