What is a jump table?

JeffV picture JeffV · Sep 7, 2008 · Viewed 38.9k times · Source

Can someone explain the mechanics of a jump table and why is would be needed in embedded systems?

Answer

Josh Segall picture Josh Segall · Sep 7, 2008

A jump table can be either an array of pointers to functions or an array of machine code jump instructions. If you have a relatively static set of functions (such as system calls or virtual functions for a class) then you can create this table once and call the functions using a simple index into the array. This would mean retrieving the pointer and calling a function or jumping to the machine code depending on the type of table used.

The benefits of doing this in embedded programming are:

  1. Indexes are more memory efficient than machine code or pointers, so there is a potential for memory savings in constrained environments.
  2. For any particular function the index will remain stable and changing the function merely requires swapping out the function pointer.

If does cost you a tiny bit of performance for accessing the table, but this is no worse than any other virtual function call.