[Home] [Groups] - Message: [Prev in Group] [Next in Group]

nu.kanga.list.mud-dev

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

[Full Header] [Plain Text]
From: Chris Gray <cg@ami-cg.GraySage.Edmonton.AB.CA>
Newsgroups: nu.kanga.list.mud-dev
Date: Sun, 7 Feb 1999 23:10:13 -0700
Organization: Kanga.Nu
[Jon A. Lambert, replying to Ben Greear:]

 >> 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.

 >Instead of the array mapping to enums, why not map to funtion pointers?

Agreed. There doesn't seem to be any reason to go to an enum. If you
need additional information besides a pointer to the handling function,
you can use a pointer to a struct containing the additional info as well
as a pointer to the handling function.

I essentially do that, although I "point to" MUD code rather than
native code.

--
Don't design inefficiency in - it'll happen in the implementation. - me

Chris Gray     cg@ami-cg.GraySage.Edmonton.AB.CA
               http://www.GraySage.Edmonton.AB.CA/~cg