Hansi | 15 Jul 09:21

Beginner design question

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
John Femiani | 15 Jul 10:01
Favicon

Re: Beginner design question

> 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
Zeljko Vrba | 15 Jul 10:23
Favicon

Re: Beginner design question

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 | 15 Jul 10:38

Re: Beginner design question

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.
gast128 | 15 Jul 14:57
Favicon

Re: Beginner design question

Hansi <hansipet <at> web.de> writes:

> 
> 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
vicente.botet | 15 Jul 17:50

Re: Beginner design question

----- Original Message ----- 
From: "Hansi" <hansipet <at> web.de>
To: <boost-users <at> lists.boost.org>
Sent: Tuesday, July 15, 2008 9:24 AM
Subject: [Boost-users] Beginner design question

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?

--
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 
Hansi | 16 Jul 07:22

Re: Beginner design question


> 
> -- 
> 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

Gmane