Jump to content
  • Advertisement
Sign in to follow this  
akuda

(C++) WinApi: switch(message) optimisation?

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

Hi, I wonder, if the "switch" instructions (considering ex. 200 "case"s) is anyhow optimised by the compiler, or should it be optimised with some kind of binary tree? The compiler I'm most interested about is MS Visual C++ family, but any information would be considered useful :). Regards, akuda

Share this post


Link to post
Share on other sites
Advertisement
IIRC A switch is just a lookup into a jump table. If a switch statement is the biggest bottleneck in your game I'd like to offer you a 2 million dollar salary because you are the best programmer in the world [smile] (i.e in no way should you worry about such tiny micro optimizations until you absolutely identify it as a problem through profiling)

-me

Share this post


Link to post
Share on other sites
For dense case statement values it'll be a jump table. For sparse case values it may generate either a binary search or a series of compares depending on the number of cases. This is typical of most optimizing compilers.

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!