encyclopegia.org

Dispatch table

In computer science, a dispatch table is a data structure that maps a series of known actions to their corresponding code, which can later be retrieved dynamically. This structure is commonly implemented either using an associative array to directly map method names to a corresponding function pointer, or a simple array of function pointers with known indices. Common use cases include the implementation of late binding and virtual polymorphism in object-oriented programming and the implementation of system calls.

In computer science, a dispatch table is a data structure that maps a series of known actions to their corresponding code, which can later be retrieved dynamically. This structure is commonly implemented either using an associative array to directly map method names to a corresponding function pointer, or a simple array of function pointers with known indices. Common use cases include the implementation of late binding and virtual polymorphism in object-oriented programming and the implementation of system calls. In operating system kernel design, system calls are commonly implemented using a dispatch table of indices mapping to corresponding privileged system actions. For example, in Linux, the sys_exit system call has an index of 60, and can be called by passing 60 into the appropriate processor register and triggering a program interrupt. Calls sys_exit with exit code 0 mov rax, 60 mov rdi, 0 syscall Since system calls only require a number to reference the underlying kernel action, they can be called from user space while in reality triggering code in kernel space. This improves system security by ensuring that privileged code can only be run through the narrow interface that each call provides. 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". // Dispatch table of actions as well as a fallback const actions = { action1() { console.log("action1 called"); }, action2() { console.log("action2 called"); }, action3() { console.log("action3 called"); }, fallback() { console.log("fallback called"); } }; function performAction(key) { const action = Object.hasOwn(actions, key) ? key : "fallback"; return actions[action](); } performAction("action1"); // outputs "action1 called" performAction("action3"); // outputs "action3 called" performAction("action5"); // outputs "fallback called" In Lua, tables can store any value, including functions, making it trivial to implement a simple dispatch table. -- Dispatch table of actions as well as a fallback local actions = { action1 = function () print('action1 called') end, action2 = function () print('action2 called') end, action3 = function () print('action3 called') end, fallback = function () print('fallback called') end } function perform_action(key) if actions[key] ~= nil then return actions[key]() end return actions.fallback() end perform_action('action1') -- outputs "action1 called" perform_action('action3') -- outputs "action3 called" perform_action('action5') -- outputs "fallback called"

References

No reference rows published for this article.

Cite this article

MLA

"Dispatch table." encyclopegia.org, 2026, https://encyclopegia.org/wiki/dispatch-table. Accessed 24 November 2026.

Chicago

"Dispatch table." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/dispatch-table.

APA

encyclopegia.org. (2026). Dispatch table. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/dispatch-table

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Purple Rain (film)

enwiki · references available

Glenn Shafer

enwiki · references available

The Times of India

enwiki · references available

Dementia with Lewy bodies

enwiki · references available

Henry Mintzberg

enwiki · references available

São Paulo (state)

enwiki · references available

Paul Bremer

enwiki · references available

Apidae

enwiki · references available

Apoidea

enwiki · references available

New Army

enwiki · references available

Title (property)

enwiki · references available

Prandtl–Glauert singularity

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1365382304 · 0.5 · snapshot enwiki-001365382304

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.