Hi Chris,
Chris 'Xenon' Hanson schrieb:
Peter Hrenka wrote:
Nothing needs to be virtual here. It's just a template class
with overloaded operators which means everything is effectively
inlined. We could also use an "unsigned int" as internal storage type
(Qt seems to use a signed int).
But doesn't RTTI embed a hidden pointer (similr to the vftbl) into every
class as well,
that points to the common per-class ID/metadata?
Boy, you're paranoid. Well, sometimes that's a good thing ;-)
My understanding is that as long as you do not have virtual
methods or derive (directly or indirectly) from a class that
has virtual methods, there is no overhead in the memory layout
of the class instances.
But of course, I cannot guess what stange compilers will do...
The example programm gives me the following output on
64-bit gcc on Linux:
EnumSize: 4
EnumFlagsSize: 4
EnumFlagsArraySize: 40
PlainClass: 4
VirtualClass: 16
So the template class does not use more memory than the plain enum
(on this platform).
I guess quibbling about an extra pointer is very old-skool 80s coder of me.
You can have
my VIC-20 when I'm done porting OpenGL ES 1.0 to it! ;)
No, your concerns are valid. As you can see the virtual method adds a
factor of 4 in memory usage to the "VirtualClass" as compared
to the "PlainClass" in the example.
Cheers,
Peter
--
Vorstand/Board of Management:
Dr. Bernd Finkbeiner, Dr. Roland Niemeier,
Dr. Arno Steitz, Dr. Ingrid Zech
Vorsitzender des Aufsichtsrats/
Chairman of the Supervisory Board:
Michel Lepert
Sitz/Registered Office: Tuebingen
Registergericht/Registration Court: Stuttgart
Registernummer/Commercial Register No.: HRB 382196
#include <iostream>
enum MyFlags {
ONE = (1<<0),
TWO = (1<<1),
TREE = (1<<2)
};
template<class enumType>
class EnumFlags {
private:
unsigned int _flags;
};
class PlainClass {
void foo() {}
int _data;
};
class VirtualClass {
virtual void foo() {}
int _data;
};
int main(int argc, char* argv[]) {
std::cout << "EnumSize: " << sizeof(MyFlags) << std::endl;
std::cout << "EnumFlagsSize: " << sizeof(EnumFlags<MyFlags>) << std::endl;
EnumFlags<MyFlags> enumArray[10];
std::cout << "EnumFlagsArraySize: " << sizeof(enumArray) << std::endl;
PlainClass p;
VirtualClass v;
std::cout << "PlainClass: " << sizeof(p) << std::endl;
std::cout << "VirtualClass: " << sizeof(v) << std::endl;
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org