Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Tree Penguin

Classes when compiled...

This topic is 5273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Well the compiler may do some funny things with memory allignment or something but you don''t need to worry about these things.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!