Sign in to follow this  

Code paths

This topic is 4843 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 have a CVector class with different code paths optimized for various cpu features. Features like 3D Now, SSE, SSE2. I also have a path that supports standard C++ in case none of those features are supported. The code path is chosen based on another class called CPUTest. This class just checks what type of processor is being used and what type of SIMD it supports. I accomplish the path switching using function pointers. All this works fine except... I don't know how to tie the two classes together without calling the CPUTest class functions over and over again. Every time I create an object of my CVector class, it needs to call the CPUTest functions for SIMD support. That's not what I want. So what's the best way to tell my CVector class what path to choose without having to run the CPUTest every time a CVector object is created?

Share this post


Link to post
Share on other sites
have a static member function within your class that you run once at startup to set the function pointers for the whole class, and then just use the static function pointers that C-Junkie suggested.

That way you wont even have to check whether or not the static has been set you'll just be able to use it. Obviously use asserts in your code to catch unassigned function pointers in debug mode [smile]

i think anyway, sounds like quite a good system already though.

Andy

Share this post


Link to post
Share on other sites

This topic is 4843 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.

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