[MUD-Dev] Re: Question on c++ switch optimization, and parsers i

Ben Greear greear at cyberhighway.net
Mon Feb 8 19:18:11 CET 1999


Jon A. Lambert wrote:
> 
> On  7 Feb 99, Ben Greear wrote:
> >
> > Basically, I'll have a bunch of classes hashed into an array
> > that will contain the keywords mapped to an enum.
> >
> > Now, I get the enum, and then I need to call the various commands
> > that the enum maps to.
> >
> > Currently, I'm using a huge (~400 cases) switch statement.
> >
> > So, the question is:  Is that efficient?  Does the compiler
> > generate code that does better than a linear search down the
> > case statements?  If not, I can manually hack a sort of n-ary
> > tree performance into it, but I'd wrather not if I can help it.
> >
> > Also, I'll be curious if anyone wants to spew forth their own ideas
> > on how to parse user's commands into callable methods.
> >
> 
> Instead of the array mapping to enums, why not map to funtion pointers?

Cause all my methods have different signatures..

Instead, I think I'll wrap each one in a class inherited from one that
has a single execute() method, which will call my real method.  Gonna
have
to create a bunch of little classes...but that's just typing...

Ben


 --
> --*     Jon A. Lambert - TychoMUD       Email:jlsysinc at .ix.netcom.com      *--
> --*     Mud Server Developer's Page <http://pw1.netcom.com/~jlsysinc>      *--
> --* I am the Dragon of Grindly Grund, but my lunches aren't very much fun, *--
> --* For I like my damsels medium rare, And they always come out well done. *--

--
Ben Greear (greear at cyberhighway.net)  http://www.primenet.com/~greear 
Author of ScryMUD:  mud.primenet.com 4444        (Released under GPL)
http://www.primenet.com/~greear/ScryMUD/scry.html




More information about the mud-dev-archive mailing list