Branch Table - Advantages

Advantages

Advantages of branch tables include:

  • compact code structure (despite repeated branch opcodes)
  • reduced source statements (versus repetitive If statements)
  • reduced requirement to test return codes individually (if used at call site to determine subsequent program flow)
  • Algorithmic and code efficiency (data need only be encoded once and branch table code is usually compact), and the potential to attain high data compression ratios. For example, when compressing country names to country codes, a string such as "Central African Republic" can be compressed to a single index, resulting in large savings – particularly when the string appears many times. In addition, this same index can be used to access related data in separate tables, reducing storage requirements further.

For library functions, where they may be referenced by an integer:

  • improve compatibility with subsequent software versions. If the code of a function and the address of its entry point is changed, only the branch instruction in the branch table needs to be adjusted, application software compiled against the library, or for the operating system, does not need modification.

In addition, calling functions by number (the index into the table), can sometimes be useful in some cases in normal application programming

Read more about this topic:  Branch Table

Famous quotes containing the word advantages:

    A woman might claim to retain some of the child’s faculties, although very limited and defused, simply because she has not been encouraged to learn methods of thought and develop a disciplined mind. As long as education remains largely induction ignorance will retain these advantages over learning and it is time that women impudently put them to work.
    Germaine Greer (b. 1939)

    There is no one thoroughly despicable. We cannot descend much lower than an idiot; and an idiot has some advantages over a wise man.
    William Hazlitt (1778–1830)

    To say that a man is your Friend, means commonly no more than this, that he is not your enemy. Most contemplate only what would be the accidental and trifling advantages of Friendship, as that the Friend can assist in time of need by his substance, or his influence, or his counsel.... Even the utmost goodwill and harmony and practical kindness are not sufficient for Friendship, for Friends do not live in harmony merely, as some say, but in melody.
    Henry David Thoreau (1817–1862)