Classes when compiled...

Started by
2 comments, last by Tree Penguin 19 years, 10 months ago
Hi, when you use 2 classes, for example like these: class CVertex { public: float x,y,z; void Set(float _x,float _y,float _z); }; class CNormal { public: float x,y,z; void Set(float _x,float _y,float _z); void Normalize(); }; Would it be faster in runtime when doing it with just one class like this: class CVertex { public: float x,y,z; void Set(float _x,float _y,float _z); void Normalize(); }; Or does it not make any difference? Thanks in advance. Also i was wondering if there is a difference between having variables of classes in a parent class and having all variables all together in one (this sounds confusing i think, i mean this) : class CPoint { public: CVertex v; CNormal n; }; so if that's slower than this: class CPoint { public: float x,y,z; float nx,ny,nz; }; And in what amount. I guess it all doesn't matter really much but just to be sure and out of interest. Thanks [edited by - Tree Penguin on June 7, 2004 6:09:28 PM]
Advertisement
I don't believe either of those things will show any speed difference. You really don't need to worry about the speed of things like this, it's just premature micro-optimization which is pointless.

Oh and an explination as to why they're the same speed:

1.
class CVertex {public:float x,y,z;void Set(float _x,float _y,float _z);};class CNormal {public:float x,y,z;void Set(float _x,float _y,float _z);void Normalize();};  


Both of these classes when compiled will take up exactly the same amount of memory and have exactly the same structure in memory, it's just with CNormal you can call Normalize in your C++ code.

2.
class CPoint {public:CVertex v;CNormal n;};class CPoint {public:float x,y,z;float nx,ny,nz;};  


Again they're both exactly the same when compiled.

[edited by - Monder on June 7, 2004 6:49:39 PM]
Ok, so it''s compiled so that all variables are stored together, just a block of memory. Thanks
Well the compiler may do some funny things with memory allignment or something but you don''t need to worry about these things.

This topic is closed to new replies.

Advertisement