Dispatch table

Dispatch table

In computer science, a dispatch table is a table of pointers to functions or methods. Use of such a table is a common technique when implementing late binding in object-oriented programming.

Perl implementation

The following shows one way to implement a dispatch table in Perl, using a hash to store references to code (also known as function pointers).

#define the table using one anonymous code-ref and one named code-ref
my %dispatch = (
  "-h" => sub {  return "hello\n"; },
  "-g" => \&say_goodbye
);

sub say_goodbye {
  return "goodbye\n";
}

#fetch the code ref from the table, and invoke it
my $sub = $dispatch{$ARGV[0]};
print $sub ? $sub->() : "unknown argument\n"; 

Running this Perl program as perl greet -h will produce "hello", and running it as perl greet -g will produce "goodbye".

Virtual method tables

In object-oriented programming languages that support virtual methods, the compiler will automatically create a dispatch table for each object of a class containing virtual methods. This table is called a virtual method table or vtable, and every call to a virtual method is dispatched through the vtable.

References


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • System Service Dispatch Table — ou SSDT, est un tableau de descripteur de service situé dans le Noyau de Windows, utilisé pour diriger des appels système vers un traitement approprié : table d adressage des API. Point d accroche dans la table SSDT Le… …   Wikipédia en Français

  • Dispatch box — A dispatch box, or despatch box, is a box for holding official papers and transporting them from place to place.In the United Kingdom such boxes, looking roughly like briefcases, are traditionally red, bear the monogram of the sovereign, and are… …   Wikipedia

  • dispatch box — n 1. (in British political life) a red leather case in which important papers are delivered to senior government ministers. It is traditional for the Chancellor of the Exchequer to hold his dispatch box up in the air for photographers and… …   Universalium

  • dispatch box — di spatch box n BrE 1.) the dispatch box a box on a central table in the British Parliament, which important members of parliament stand next to when they make speeches 2.) a box for holding official papers …   Dictionary of contemporary English

  • dispatch box — noun 1 (C) a box for holding official papers 2 the dispatch box a box on a central table in the British Parliament next to which important members of parliament stand to make speeches …   Longman dictionary of contemporary English

  • Dispatch Tabellen — Die Tabelle virtueller Methoden (engl.: virtual method table, kurz VMT, vtbl oder vtable) ist ein Ansatz von Compilern objektorientierter Programmiersprachen dynamisches Binden umzusetzen. Das ist unter anderem Grundvoraussetzung für Vererbung… …   Deutsch Wikipedia

  • Virtual method table — A virtual method table, virtual function table, dispatch table, or vtable, is a mechanism used in programming language to support dynamic dispatch (or run time method binding).Suppose a program contains several classes in an inheritance hierarchy …   Wikipedia

  • Dynamic dispatch — Theories and practice of polymorphism Double dispatch Multiple dispatch Operator overloading Polymorphism in computer science Polymorphism in OOP Subtyping Vir …   Wikipedia

  • Branch table — In computer programming, a branch table (sometimes known as a jump table) is a term used to describe an efficient method of transferring program control (branching) to another part of a program (or a different program that may have been… …   Wikipedia

  • System Service Descriptor Table — System Service Dispatch Table Cet article fait partie de la série Programmes malveillants Virus Cabir MyDoom.A Tchernobyl …   Wikipédia en Français

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”