Jump to content
  • Advertisement
Sign in to follow this  
kobe bryant

Why are C++ classes so slow

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

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

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!