Jump to content
  • Advertisement

Archived

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

Silly_con

C++ question

This topic is 5653 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

Is slow a class with much functions and much overloaded operators than other with much less functions/operators? if yes, how much? it is a good programming habit to include functions in a class that are used very few times?

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Silly_con
Is slow a class with much functions and much overloaded operators than other with much less functions/operators? if yes, how much?
i don''t know how much it is going to slow down the computer. if it does, you won''t notice it.
quote:
it is a good programming habit to include functions in a class that are used very few times?
it''s natural.


Current project: 2D in Direct3D engine.
% completed: ~35%
Status: Active.

Share this post


Link to post
Share on other sites
The only time performance issues arise from having large classes is when you are passing them around by value. It really doesn''t matter how many members and/or functions you have in your class, since there''s only ever one copy of the function code, and it just gets called with different this pointers.

Also, I wouldn''t suggest allocating extremely large classes on the stack. Use heap functions (operators new/delete, malloc/free) for exceptionally large classes.

Share this post


Link to post
Share on other sites
the question was about large numbers of FUNCTIONS and OPERATORS ... the answer is NO, a program in which you have 20 C style functions, and a small struct which you pass to those functions, is EXACTLY the same performance wise if you put those 20 functions into the class as member functions / overloaded operators ... there is NO performance penalty for using member function or overloaded operators (assuming you would need to pass the struct pointer in the first place) ... and member functions do NOT increase the size of the object at all ...

IF you use any VIRTUAL member function in a class, then the class objects get bigger by ONE POINTER (32 bits on most machines), and as you add more virtual functions, no more overhead is added to each instance ...

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!