Jump to content
  • Advertisement
Sign in to follow this  
GroZZleR

[.net] How fast is "is"?

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

Hey all, I'm working on a message based game engine, and I'm having handlers identify their messages with the "is" keyword. How much of a performance hit is this going to cost me? Here's basically what the heirarchy looks like:
IMessage
   IEntityMessage
      CreateEntityMessage
      KillEntityMessage
   ISoundMessage
      PlaySoundMessage
Every message is posted to a singleton Message Centre and the handlers subscribe to that centre to listen for messages. This gives the added benefit of handlers able to react to certain things. For example, the sound message might have a location and the entity handler might have AI react to the sound. Here's the gist of how I check message types:
	public class EntityHandler : BaseMessageHandler
	{
		public static EntityCreateMessage createMessage = new EntityCreateMessage();

		public override void Receive(IMessage message)
		{
			if(message is EntityCreateMessage)
			{
				EntityCreateMessage msg = (EntityCreateMessage)message;

				System.Windows.Forms.MessageBox.Show("Message Received!");
			}
		}

	}
I'm thinking that the "if(message is EntityCreateMessage)" is really going to end up being a bottleneck, since it's a lot of boxing / unboxing comparisons. Potentially, 100s of messages could be flying around every second. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Profile it and see. is is going to use basic reflection to determine if the type is of the type specified. But short of profiling it IN the environment, you won't really know if it's going to be a bottleneck.

Just throwing a few hundred messages at it at once is not a way to profile, you must make sure that the test case matches the environment fairly closely.

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!