S
steve
I am writing for game application. Performance is an issue.
Any advise would be appreiciated.
Any advise would be appreiciated.
steve said:I am writing for game application. Performance is an issue.
steve said:I am writing for game application. Performance is an issue.
Any advise would be appreiciated.
Yea. Put the type into the base class.
steve said:I am writing for game application. Performance is an issue.
Any advise would be appreiciated.
steve said:I am writing for game application. Performance is an issue.
Any advise would be appreiciated.
steve said:I am writing for game application. Performance is an issue.
Any advise would be appreiciated.
steve said:I am writing for game application. Performance is an issue.
Any advise would be appreiciated.
PKH said:I'm using the following approach in a game I'm working on. By inlining the
RequestClass functions it should be quite fast. (I posted this earlier in
another thread )
steve said:I am writing for game application. Performance is an issue.
Any advise would be appreiciated.
Peter Koch Larsen said:PKH said:I'm using the following approach in a game I'm working on. By inlining
the
RequestClass functions it should be quite fast. (I posted this earlier in
another thread )
[snip]
You answered the question: is it possible to detect the object run time
type
without using dynamic_cast. I see that it is. Could you also demonstrate
that it is faster than dynamic_cast? (In that case you should quote the
compiler and settings used)
/Peter
Niklas said:Well, the first bit of advice would be to carefully consider whether
you actually need to know the actual type. In general, you should try
to design things so that when you have, say, a pointer-to-Shape you
only need to do Shape things to it and don't really care whether the
object's actual type is Triangle, Ellipse, or Rhombus.
However, assuming you've already considered all that and really do
need to know the type, you have two choices: dynamic_cast and typeid.
It's possible that one is faster than the other. You should probably
test both and see.
They do slightly different things: dynamic_cast will tell you whether
the object's type is *compatible* with the specified type; typeid
tells you the specific type. The following program illustrates the
difference:
#include <iostream>
class A { public: virtual ~A() {} };
class B : public A {};
class C : public B {};
#define TEST(expr) std::cout << #expr " --> " << (expr) << '\n'
int main()
{
C obj;
A* p = &obj;
TEST( dynamic_cast<B*>(p) != 0 );
TEST( dynamic_cast<C*>(p) != 0 );
TEST( typeid(*p) == typeid(B) );
TEST( typeid(*p) == typeid(C) );
return 0;
}
The output is:
dynamic_cast<B*>(p) != 0 --> 1
dynamic_cast<C*>(p) != 0 --> 1
typeid(*p) == typeid(B) --> 0
typeid(*p) == typeid(C) --> 1
I am writing for game application. Performance is an issue.
Any advise would be appreiciated.
steve said:I am writing for game application. Performance is an issue.
Any advise would be appreiciated.
PKH said:I'm using the following approach in a game I'm working on. By inlining the
RequestClass functions it should be quite fast. (I posted this earlier in
another thread )
[snip]
You answered the question: is it possible to detect the object run time type
without using dynamic_cast. I see that it is. Could you also demonstrate
that it is faster than dynamic_cast? (In that case you should quote the
compiler and settings used)
JKop said:Jason Heyes posted:
No No No! This is clearly an instance in which one would
work with a pointer to a pointer to the *DERIVED CLASS*! To
put the type in the base clase is simply ludicrious!
Wow, do people still write code like that? How about a little type safetyMike Smith said:#define CLASS_ID_BASE 0
#define CLASS_ID_DERIVED_A 1
#define CLASS_ID_DERIVED_B 2
/* ... */
and so on. With such a system, an application that has a Base *p can
call p->GetClassID() to obtain type info. The OP indicated that speed
was an issue; in this scenario the program can switch() on the value
returned from GetClassID(), or use it as an array index, etc.
Xenos said:Wow, do people still write code like that? How about a little type safety
and easier maintainability?
enum class_id_type {
CLASS_ID_BASE,
CLASS_ID_DERIVED_A,
CLASS_ID_DERIVED_B
};
You think switching on a class id is "better" or faster than just calling a
virtual member?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.