Sign in to follow this  
Whiles

Math Classes: Templated or Not ?

Recommended Posts

Hello! I am going to rewrite some parts of my math library and... Do you think is it better to write templated math classes for future proofing ? ( I am referring in particular to vectors, matrices classes, etc... ) Could templates affect engine performance ? Are they slower ? Thanks for your answers... Bye!

Share this post


Link to post
Share on other sites
Whether your classes need to be templates or not is based on what you want your library to do. However, using templates will not affect your runtime performance in any way; template instantiation happens at compile-time.

Share this post


Link to post
Share on other sites
I think both KISS and YAGNI apply here. You will most likely need a matrix and a vector, so just write one of each, 4x4 and 4, respectively, that are composed of floats. Go about your business. If it turns out that you need both float and double versions, go ahead and make them templates.

Share this post


Link to post
Share on other sites
Quote:
Original post by Whiles

Could templates affect engine performance ? Are they slower ?


Depending on the compiler, they can result either in faster or slower code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this