Jump to content
  • Advertisement
Sign in to follow this  
thedodgeruk

how much faster are structs comparied to classes in c++

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

thinking about changing some of my classes to structs , but would have to do some messing with some code.. are structs any faster or are they about the same to create and delete.



Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by thedodgeruk
thinking about changing some of my classes to structs , but would have to do some messing with some code.. are structs any faster or are they about the same to create and delete.


There is no difference. Data is data. What did you expect?

With classes it is more usual to add constructors (perhaps some initialization "overhead") etc, but you can just as well for structs.

Share this post


Link to post
Share on other sites
The only difference between structs and classes in C++ is that struct members are default public whereas class members are default private

-me

Share this post


Link to post
Share on other sites
There is no real difference between classes and structures in C++. The only difference is that classes default to private membership access and private inheritance, whereas a struct defaults to public membership and public inheritance.

Please, do not try to optimise until you understand how performance works. We optimise by writing a correct program, testing if it is fast enough, profiling for bottlenecks and then eliminating the bottlenecks with algorithmic changes if possible, otherwise with lower level optimisations. If you do not understand how the Pareto Principle applies to your program then your "optimisations" will make no difference apart from probably causing more bugs.

If experience has thought me one thing: 99% of the time you try to guess your bottleneck you will be wrong.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!