Sign in to follow this  

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

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this