Boost logo

Boost Users :

Subject: [Boost-users] [boost][serialization] void_upcast is very slow
From: Jacob (jacobholm_at_[hidden])
Date: 2008-12-03 02:53:55


The original "inline void_upcast" method checks if the pointer to the
object is of the right type, by traversing its parents. This is
necessary when using multiple inheritance, since in such a case the
adress of the pointer to the object can vary depending on which base
class it is cast to.

While profiling one of my projects I noticed that most of the time was
spent in the void_upcast method. I modified the method to return the
pointer directly(see below), resulting in a high performance increase.
This "solution" is possible if you avoid multiple inheritance all
together, which I did. In my particular project I experienced a 75%
speed increase implementing this, going from about 10 seconds to 2.5
seconds.

Would it be possible to implement some functionality to turn on and off
the upcasting for given classes, kind of like the tracking of objects is
currently administrated?

Modified "inline void_upcast":

/inline void *
void_upcast(
  extended_type_info const & derived,
  extended_type_info const & base,
  void * const t
){
  return const_cast<void*>(t);
}/

Yours sincerely,

Jacob Holm


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net