Why Trust Techopedia

What Does Thunk Mean?

A thunk, in a general computing context, is a piece of low-level machine generated code that implements the details of a software system. It is one of the following:

  1. A piece of code performing a delayed computation
  2. A feature of a virtual function table implementation
  3. A mapping of machine data from one system specific form to another for compatibility issues

Techopedia Explains Thunk

The concepts of thunk emerged in early 1961. It is a computation returning a value of the argument when executed. A call by need replaces a thunk by its return value after the first execution. Languages with late binding have lookup in run time, based on computations performed by thunk.

Nullary functions (functions which do not take arguments) in functional programming are referred to as thunk. Thunks simulate lazy evaluation and delay the function argument computation. These functions further force thunks to get actual values. Thunk may also appear naturally in the implementation of constant functions in high order programming.

Compilers of object oriented languages such as C++ generate functions termed thunks. They optimize virtual function calls in the presence of virtual or multiple inheritances.

Some instances of relocatable code use local thunks to call library functions. Dynamic library call in the code jumps to thunks in a jump table, which is further replaced by functions loading the applicable library or moves to a suitable point in an already loaded library. So a thunk in this area computes or returns previously computed and cached values. Thunks are used in software based virtual memory systems to perform a mapping from virtual to physical address. Creating a 16-bit virtual DOS machine inside a 32-bit OS is called thunking and ensures a backward compatibility with applications using old system calls.

Flat thunks use thunks translating calls from 32-bit code to 16-bit code. An intermediate code translates memory address between platforms. Microsoft has a thunking layer of itself called Win32s, which permit 32-bit Windows application to run on 16-bit Windows. The 64-bit Windows version also provides a thunking layer, WoW64, which permits using 32-bit Windows applications.


Related Terms

Margaret Rouse

Margaret jest nagradzaną technical writerką, nauczycielką i wykładowczynią. Jest znana z tego, że potrafi w prostych słowach pzybliżyć złożone pojęcia techniczne słuchaczom ze świata biznesu. Od dwudziestu lat jej definicje pojęć z dziedziny IT są publikowane przez Que w encyklopedii terminów technologicznych, a także cytowane w artykułach ukazujących się w New York Times, w magazynie Time, USA Today, ZDNet, a także w magazynach PC i Discovery. Margaret dołączyła do zespołu Techopedii w roku 2011. Margaret lubi pomagać znaleźć wspólny język specjalistom ze świata biznesu i IT. W swojej pracy, jak sama mówi, buduje mosty między tymi dwiema domenami, w ten…