boost::any question

All, I just started looking at boost::any, pretty nice. I looked at the implementation, and it uses (as you know) a pointer to an object (w/virtual methods) on the heap, and typeid to determine if conversion is possible. I understand the memory implications (a new object copied on heap). But I'd like to get a better handle on performance, namely: I'm unfamiliar with typeid - and how it's implemented. Does anyone have good pointers to how typeid is generally implemented? Or even specifically: I'm using gcc3.x on RH Linux. I'd just like to avoid/guarantee I'm not going to be hit by some O(N) look-up for using typeid a lot. thanks, TJ -- Trey Jackson tjackson@ichips.intel.com "Her hair glistened in the rain like nose hair after a sneeze." -- Chuck Smith, Woodbridge

Trey Jackson wrote: []
I'd just like to avoid/guarantee I'm not going to be hit by some O(N) look-up for using typeid a lot.
typeid lookup is constant. Isn't dynamic memory allocation hit your concern as it's not only non-constant rather it's nondeterministically non-constant? -- Maxim Yegorushkin

Maxim wrote:
Isn't dynamic memory allocation hit your concern as it's not only non-constant rather it's nondeterministically non-constant?
Yes, but if it becomes a problem, I can roll my own any and us a custom heap to help improve locality. TJ -- Trey Jackson tjackson@ichips.intel.com A kiss in Halethorpe, Md., cannot last longer than a second. -- random factoid

On Jun 7, 2004, at 7:01 PM, Trey Jackson wrote:
I'm unfamiliar with typeid - and how it's implemented.
Does anyone have good pointers to how typeid is generally implemented? Or even specifically: I'm using gcc3.x on RH Linux.
It's typically a virtual function call. The only performance problem I'd expect is due to comparison of typids, which in many cases must resort to a string comparison of the type names. Doug
participants (3)
-
Doug Gregor
-
Maxim Yegorushkin
-
Trey Jackson