Hello, I have to make a library which provides a few classes with different implementation. This classes should have a common interface. Normally I would use derived classes from the common interface, but this classes should be really fast. What is the best way to provide a common interface and to not have the overhead of polymorphic classes? Best regards Hansjörg
Hello,
I have to make a library which provides a few classes with different implementation. This classes should have a common interface. Normally I would use derived classes from the common interface, but this classes should be really fast. What is the best way to provide a common interface and to not have the overhead of polymorphic classes?
Best regards Hansjörg
I don't know about "fast", but you can use templates and specify the interface by concepts with Boost Concept Check Library (BCCL), or you could google CRTP. --John
On Tue, Jul 15, 2008 at 09:24:48AM +0200, Hansi wrote:
would use derived classes from the common interface, but this classes should be really fast.
How fast does method execution need to be? Concrete metrics is preferred, e.g., "100 million calls per second". I'd suggest that you first implement it with polymorphic classes and *prove* that it is too slow before embarking onto something more complicated.
At the moment about 1million calls per second are the target.. Zeljko Vrba schrieb:
On Tue, Jul 15, 2008 at 09:24:48AM +0200, Hansi wrote:
would use derived classes from the common interface, but this classes should be really fast.
How fast does method execution need to be? Concrete metrics is preferred, e.g., "100 million calls per second". I'd suggest that you first implement it with polymorphic classes and *prove* that it is too slow before embarking onto something more complicated.
Hansi
At the moment about 1million calls per second are the target..
I am not sure if this helps, but there are two articles on Dr Dobbs translating runtime polymorphism, to compile time construction. The downside is that it does not work in every sitaution (probably you must already know the class structure at compile time) and I have not tested it myself. If a virtual call is a bottleneck, than you have a really performance intensive application. C++ Expression Templates: http://www.ddj.com/cpp/184401627 A Different Interpretation of the Interpreter Design Pattern: http://www.ddj.com/cpp/184401605
----- Original Message -----
From: "Hansi"
-- Hi,
The question is if you need runtime polymorphism or static one? If you have some performances constraints, I propose you to use static polymorphism as far as you can and switch to runtime polymorphism when statics no work any more. The Adobe Poly library helps you to make the switch (see http://stlab.adobe.com/wiki/images/c/c9/Boost_poly.pdf and http://homepages.fh-regensburg.de/~mpool/mpool07/proceedings/5.pdf)
Hopping that helps you.
Vicente
static polymorphism helps too...thanks
participants (5)
-
gast128
-
Hansi
-
John Femiani
-
vicente.botet
-
Zeljko Vrba