Why are C++ classes so slow

Started by
4 comments, last by Cocalus 18 years, 8 months ago
I rendered a flat terrain generated with GL_QUADS inside of a function. I then decided that it would be more neater if I placed it into a modular Class structure. My game dropped by 5 frames a second. I know use the original function to render the terrain. So my question is how can I stop my terrain class from slowing down my game so much, if I cant then what is benefical about using classes except from giving more structure to your code and allowing you to write less code. Thanx for any advice.
Advertisement
Your question is missing information. Classes are not slow, the way you use them (which is probably wrong) is slowing down your application. For example if you are creating them with new and you release them with delete on every frame, it's reasonable your performance will be bad. If you have heavy ctors/dtors - your performance will go down. etc. etc.

If you want, upload your code and let's take a look.
Dubito, Cogito ergo sum.
You probably are doing silly things like generating spurious temporaries, having unnecessary virtual functions or scoping objects poorly. Or possilby you are profiling a debug build which generally will lose frames per second at the drop of a hat. Without knowing how you coverted your code to use classes it's impossible to say why your code now runs more slowly.
The class itself aren't making your code drop with 5 fps, unless you had something like 10000 fps before. It is probably your use of classes which makes your program loose 5 frames per second, of course if you have a really old/bad compiler it might be better at optimizing functions, but this isn't likely.
I cant upload my code now beacuse I haven't got the internet in my house but when i,m able to, I,ll private message it to you (DadleFish).

Thanx.
5 FPS from what? There's a HUGE difference between a drop from 1000-995 and 10-5.
More info Here

Is the difference small like the 1000-995 from above. Most likely you didn't use classes properly, but its hard to tell without the source or at least a better description.

How are you using the GL_QUADS, with the slow immediate mode, like glbegin(GL_QUADS);glvertex(...);etc;glend(); Or are you using display lists,vertex arrays and/or VBOs?

This topic is closed to new replies.

Advertisement