S
srp113
Hi,
I have a base class (State) that has a list of virtual/non-virtual
functions that implement processing logic for different kinds of
events that can happen in a system (signature for all of these
functions is same). I want to build a jump table (lets say a simple
array) that maps an event(integer) to a member function pointer:
jumptable[eventid]->fptr(eventdata).
I have classes responding to these events derived from base "State"
class (the hierarchy can have depth of > 2 i.e. State1 derives from
Base, State2 derives from State1...) and these virutal methods could
get overriden in different "state" classes to provide different
behavior for a given event. (state1/state2 both can have different
processing logic for event1 but same for event2) . My questions:
a)Will jumptable[eventid]->fptr(eventdata) work as expected? ( esp for
virtual functions will this call the most derived classes
implementation?),
b)Is there a performance penalty with this implementation (going
through 2 lookups one for jump table and then for vtable)?
c)If answer to b) is yes, are there any alternatives?
The reason for jump table is that I want to reuse this implementation
of state pattern in multiple applications
Thanks Much,
Sunil
I have a base class (State) that has a list of virtual/non-virtual
functions that implement processing logic for different kinds of
events that can happen in a system (signature for all of these
functions is same). I want to build a jump table (lets say a simple
array) that maps an event(integer) to a member function pointer:
jumptable[eventid]->fptr(eventdata).
I have classes responding to these events derived from base "State"
class (the hierarchy can have depth of > 2 i.e. State1 derives from
Base, State2 derives from State1...) and these virutal methods could
get overriden in different "state" classes to provide different
behavior for a given event. (state1/state2 both can have different
processing logic for event1 but same for event2) . My questions:
a)Will jumptable[eventid]->fptr(eventdata) work as expected? ( esp for
virtual functions will this call the most derived classes
implementation?),
b)Is there a performance penalty with this implementation (going
through 2 lookups one for jump table and then for vtable)?
c)If answer to b) is yes, are there any alternatives?
The reason for jump table is that I want to reuse this implementation
of state pattern in multiple applications
Thanks Much,
Sunil