I had a lot of research to see how function pointer works. Sometimes,
programmers choose switch keyword and function in each case block can
be called. Sometimes, they choose ordinary function pointer array
instead of switch.
They believe that ordinary function pointer is much faster than
switch. Think of one variable called selectFunction. selectFunction
variable can be the range of 0 through 1,000 or more.
Load selectFunction variable into a register. Load memory address of
ordinary function pointer array into a register. Both registers can
be added together to create indirection before one of these 1,000
functions can be called.
Member function pointer array is slower than ordinary function pointer
because first step is to load "this" pointer to locate memory address
of member function pointer array. It is likely that member function
pointer array needs to execute indirction twice before one of these
mmber function is called. Only ordinary function pionter needs one
indirection.
How can you find a way how member function pointer array can execute
one indirection instead of two indirection? A vtable has a memory
address where constructor function and deconstructor function are the
top. You can use selectFunction variable to be added to "this" pinter
in vtable memory address. Then, one of these 1,000 member functions
in the vtable can be called.
I did read C++ Lite FAQ and it does mention functionoids. They claim
that functionoids are much faster than member function poitner array.
How can it be possible to be true?
I would prefer to use static memory where member function pointer
array is stored at compile-time. I may do not need virtual functions
becaus I choose not to use dynamic binding.
Please advise which I should choose to use ordinary function pointer,
member function pointerarray, or functionoids.
Short example of code looks like this below.
int selectFunction = 0;
.....
do something ....
.....
selectFnction may be modified to have a value of 100.
.....
.....
FuncPtr [ selectFuntion ] ();
.....
100th member function is called...
Nephi