rtti

How expensive is RTTI?

不想你离开。 提交于 2019-11-26 15:38:31
I understand that there is a resource hit from using RTTI, but how big is it? Everywhere I've looked just says that "RTTI is expensive," but none of them actually give any benchmarks or quantitative data reguarding memory, processor time, or speed. So, just how expensive is RTTI? I might use it on an embedded system where I have only 4MB of RAM, so every bit counts. Edit: As per S. Lott's answer , it would be better if I include what I'm actually doing. I am using a class to pass in data of different lengths and that can perform different actions , so it would be difficult to do this using

Why does typeid.name() return weird characters using GCC and how to make it print unmangled names?

牧云@^-^@ 提交于 2019-11-26 15:13:16
How come when I run this main.cpp : #include <iostream> #include <typeinfo> using namespace std; struct Blah {}; int main() { cout << typeid(Blah).name() << endl; return 0; } By compiling it with GCC version 4.4.4: g++ main.cpp I get this: 4Blah On Visual C++ 2008, I would get: struct Blah Is there a way to make it just print Blah or struct Blah ? The return of name is implementation defined : an implementation is not even required to return different strings for different types. What you get from g++ is a decorated name , that you can "demangle" using the c++filt command or __cxa_demangle .

Why do I get “type has no typeinfo” error with an enum type

北城余情 提交于 2019-11-26 13:48:39
I have declared the following enum type in which I want the first member to have the ordinal value of 1 (one) rather than the usual 0 (zero): type TMyEnum = ( meFirstValue = 1, meSecondValue, meThirdValue ); If I call TypeInfo() , e.g. as part of a call to GetEnumName() , I get a compiler error: GetEnumName(TypeInfo(TMyEnum), Ord(aValue)); ERROR: "E2134: Type 'TMyEnum' has no typeinfo" Why is this? I know that classes only have typeinfo if they are compiled with the $M compiler option enabled or (derive from some class which was, such as TPersistent ) but I didn't think there were any special

is vs typeof

早过忘川 提交于 2019-11-26 11:54:51
问题 Which of these pieces of code is faster? if (obj is ClassA) {} if (obj.GetType() == typeof(ClassA)) {} Edit: I\'m aware that they don\'t do the same thing. 回答1: This should answer that question, and then some. The second line, if (obj.GetType() == typeof(ClassA)) {} , is faster, for those that don't want to read the article. 回答2: Does it matter which is faster, if they don't do the same thing? Comparing the performance of statements with different meaning seems like a bad idea. is tells you

dynamic_cast from “void *”

女生的网名这么多〃 提交于 2019-11-26 11:28:32
问题 According to this, void* has no RTTI information, therefore casting from void* is not legal and it make sense. If I remember correctly, dynamic_cast from void* was working on gcc. Can you please clarify the issue. 回答1: dynamic_cast works only on polymorphic types, i.e. classes containing virtual functions. In gcc you can dynamic_cast to void* but not from : struct S { virtual ~S() {} }; int main() { S* p = new S(); void* v = dynamic_cast<void*>(p); S* p1 = dynamic_cast<S*>(v); // gives an

Why does typeid.name() return weird characters using GCC and how to make it print unmangled names?

ⅰ亾dé卋堺 提交于 2019-11-26 05:57:47
问题 How come when I run this main.cpp : #include <iostream> #include <typeinfo> using namespace std; struct Blah {}; int main() { cout << typeid(Blah).name() << endl; return 0; } By compiling it with GCC version 4.4.4: g++ main.cpp I get this: 4Blah On Visual C++ 2008, I would get: struct Blah Is there a way to make it just print Blah or struct Blah ? 回答1: The return of name is implementation defined : an implementation is not even required to return different strings for different types. What

Why do I get “type has no typeinfo” error with an enum type

血红的双手。 提交于 2019-11-26 03:43:57
问题 I have declared the following enum type in which I want the first member to have the ordinal value of 1 (one) rather than the usual 0 (zero): type TMyEnum = ( meFirstValue = 1, meSecondValue, meThirdValue ); If I call TypeInfo() , e.g. as part of a call to GetEnumName() , I get a compiler error: GetEnumName(TypeInfo(TMyEnum), Ord(aValue)); ERROR: \"E2134: Type \'TMyEnum\' has no typeinfo\" Why is this? I know that classes only have typeinfo if they are compiled with the $M compiler option