Re: base classes and inheritance problem
In article <ca435243-df79-41df-b8fb-179e2b135db8
@e60g2000hsh.googlegroups.com>, zionztp@gmail.com says...
Thank you all for your replies, i will tell you a little of what i'm
trying to do so maybe you can understand why im asking this, im
working in a simple 2d graphic rendering engine, the "drawing" class
will have many functions and i wanted to implement these functions
using different APIs like something like:
N *c;
c = new A();
if(change){
delete c;
c = new B();
}
delete c;
And since some functions are called many times i was a bit worried
about a possible slowdown caused by virtual functions.
First, I'd note that I don't find your explanation particularly
revelatory -- you've said a bit about what you're doing right now, but
nothing about _why_ you're doing it. We can't suggest better ways of
doing what you want until we know what you want.
One thing that was pointed out previously in this thread remains though:
the cost of virtual a function call over a normal function call is
typically going to be something like a nanosecond. The cost of a new or
delete is typically going to be at least a microsecond (i.e. 1000 times
longer) and can easily run into the millisecond range (i.e. a million
times longer).
IOW, when you're using new or delete, adding or removing a virtual
function call is likely to affect speed by well under 1%, and quite
possibly not even by enough to measure.
--
Later,
Jerry.
The universe is a figment of its own imagination.