Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualKarsten_

Posted 26 October 2013 - 11:38 AM

One thing that is always confusing me: why do I often see people accessing vectors using "at", but don't have an actual try/catch around it? The only benefit in return for being slow is that you're sure to have an unhandled exception.


As long as the place where you use at is not run during every game loop (and uploading vertices to the graphics card really shouldn't be) then it does offer additional safety without causing any serious performance issues.
There is no reason to catch it at this point either and if you have your smart pointers set up correctly you can allow the exception to propagate and be caught somewhere more generic or useful such as "failed to load model" where it can then be properly handled.
That said, in a for loop, I don't see a point of using at because there are only a few rare cases where it will go out of bounds but using an iterator is probably faster anyway.

#3Karsten_

Posted 26 October 2013 - 11:36 AM

One thing that is always confusing me: why do I often see people accessing vectors using "at", but don't have an actual try/catch around it? The only benefit in return for being slow is that you're sure to have an unhandled exception.


As long as the place where you use at is not run during every game loop (and uploading vertices to the graphics card really shouldn't be) then it does offer additional safety without causing any serious performance issues.
There is no reason to catch it at this point either and if you have your smart pointers set up correctly you can allow the exception to propagate and be caught somewhere more generic or useful such as "failed to load model" where it can then be properly handled.
That said, in a for loop, I don't see a point of using at because it should always be in bounds but using an iterator is probably faster anyway.

#2Karsten_

Posted 26 October 2013 - 11:35 AM

One thing that is always confusing me: why do I often see people accessing vectors using "at", but don't have an actual try/catch around it? The only benefit in return for being slow is that you're sure to have an unhandled exception.


As long as the place where you use at is not run during every game loop (and uploading vertices to the graphics card really shouldn't be) then it does offer additional safety withought causing any serious performance issues.
There is no reason to catch it at this point either and if you have your smart pointers set up correctly you can allow the exception to propagate and be caught somewhere more generic or useful such as "failed to load model" where it can then be properly handled.
That said, in a for loop, I don't see a point of using at because it should always be in bounds but using an iterator is probably faster anyway.

#1Karsten_

Posted 26 October 2013 - 11:35 AM

One thing that is always confusing me: why do I often see people accessing vectors using "at", but don't have an actual try/catch around it? The only benefit in return for being slow is that you're sure to have an unhandled exception.


As long as the place where you use at is not run during every game loop (and uploading vertices to the graphics card really shouldn't be) then it does offer additional safety.
There is no reason to catch it at this point either and if you have your smart pointers set up correctly you can allow the exception to propagate and be caught somewhere more generic or useful such as "failed to load model" where it can then be properly handled.
That said, in a for loop, I don't see a point of using at because it should always be in bounds but using an iterator is probably faster anyway.

PARTNERS