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

Started by
2 comments, last by rip-off 13 years, 4 months ago
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.



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.
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
The only difference between structs and classes in C++ is that struct members are default public whereas class members are default private

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

This topic is closed to new replies.

Advertisement