PDA

View Full Version : C++ Exceptions & OpenGL performance



biot023
04-30-2003, 11:32 PM
Hallo.
Having only just recently got the hang of exceptions, I'm keen to utilise them, but I do know that there is some performance overhead associated w/ their use.
I don't know how much, though.
If I just ran everything in a try...catch block from the outset, would this effect speed too adversely (or at all)?
Or would peolpe reccommend using assert until I'm very confident of my code, then turning it off?
I hate passing bools everywhere, cuz I always lose track of them.
Cheers for any input,
Doug.

mikael_aronsson
05-01-2003, 01:35 AM
Hi !

The use of exceptions increase the size of the executable, but as long is not exception is thrown your code should run pretty much at the same speed as without the exception code.

Mikael

biot023
05-01-2003, 02:10 AM
Thanks alot, man - I'll get using them, then!
Cheers,
Doug.

starman
05-01-2003, 07:41 AM
But be careful not to overuse them. Exceptions should be used for "exceptional" conditions -- things that are supposed to work but don't -- not as a substitute for return codes. Some examples (assuming you're developing a game):

- If you can't open your game's .ini or .cfg file, that's an exception

- If you fail to create a rendering context in Windows, that's an exception

- If the player tries to open a door for the next room but it's locked, that's NOT an exception, it's an expected response.

I work with Java programmers who throw exceptions around like return codes. Nothing more than a glorified "goto" if you use them that way.

biot023
05-01-2003, 10:43 PM
Yeah - cheers, man.
I'll only use them for major problems - good to hear a cautionary voice, nonetheless, cuz I have a lazy reflex like you wouldn't believe.
Cheers,
Doug.