Thunk

thunk:PC計算機中典型的形實轉換程式。在電腦里,為了執行指令,需要在記憶體段地址和平坦地址之間進行轉換。當16位應用程式在32位地址空間進行運行的時候,應用程式的16位段地址必須轉化成32位平坦地址,這時候thunk是很容易見到的。另外,如果一個32位程式呼叫一個16位DLL,那么thunk就存在於相反的方向:從32位轉變成16位。

基本介紹

  • 中文名:Thunk
  • 解釋:形實轉換程式
  • 發明者:P.Z.Ingerman
  • 套用系統:WINDOWS
  • 程式類別:函式
  • 誕生時間:1961年
基本解釋,詳盡解釋,

基本解釋

簡單的說叫 形實轉換程式,給一個類創建對象,這是我的理解。而在WINDOWS裡邊意味著16/32位程式的轉換。

詳盡解釋

thunk中英解釋
In a PC, to execute the instructions required to switch between segmented addressing of memory and flat addressing. A thunk typically occurs when a 16-bit application is running in a 32-bit address space, and its 16-bit segmented address must be converted into a full 32-bit flat address. On the other hand, if a 32-bit program calls a 16-bit DLL, then the thunk is in the opposite direction: from 32 bit to 16 bit.
相關的歷史
thunk
1. [obs.]“A piece of coding which provides an address:”, according to P. Z. Ingerman, who invented thunks in 1961 as a way of binding actual parameters to their formal definitions in Algol-60 procedure calls. If a procedure is called with an expression in the place of a formal parameter, the compiler generates a thunk which computes the expression and leaves the address of the result in some standard location.
“只是編寫可提供地址的代碼的一部分:”,P.Z.Ingerman如是說。他是在1961年發明這個定義的。當時是定義這樣一個方法:把實際參數綁定到在Algol-60程式里呼叫到的定義。如果一個程式在被呼叫的時候,用一個表達式占據了形參的位置,那么編譯器就會產生一個thunk,這個thunk指的是:計算表達式的地址,然後把這個地址放在適宜的位置。
2. Later generalized into: an expression, frozen together with its environment, for later evaluation if and when needed (similar to what in techspeak is called a closure). The process of unfreezing these thunks is called forcing.
過了不久,它的意思就擴大了:一個表達式,被它所在的環境所限制,在需要的時候重新計算這個表達式的值(有點象techspeak里的closure(關於closure參考下面。))。完成這些thunks的過程就稱為forcing。(什麼東東?強迫?暴力?望指教)
3. A stubroutine, in an overlay programming environment, that loads and jumps to the correct overlay. Compare trampoline.
stubroutine(stub subroutine的縮寫,是subroutine(參考後文)的占位符,通常很小,或者為空,在後來被充實),通常存在於外殼編程環境,它裝載並跳轉到正確的外殼。好比蹦床。
4. Microsoft and IBM have both defined, in their Intel-based systems, a “16-bit environment” (with bletcherous segment registers and 64K address limits) and a “32-bit environment” (with flat addressing and semi-real memory management). The two environments can both be running on the same computer and OS (thanks to what is called, in the Microsoft world, WOW which stands for Windows On Windows). MS and IBM have both decided that the process of getting from 16- to 32-bit and vice versa is called a “thunk”; for Windows 95, there is even a tool THUNK.EXE called a “thunk compiler”.
Microsoft和IBM對它都進行了定義,在基於Intel的系統里,一個“16位環境”(使用bletcherous的段暫存器,並且有64K地址的限制)和一個“32位環境”(使用平坦地址,並且實現半真實記憶體管理功能)。這兩個環境都能在同樣的電腦和OS(顧名思義,在Microsoft的世界,WOW指的是Windows On Windows)。MS和IBM都決定把---從16位到32位和32位到16位的轉變---叫做“thunk”;
就Windows 95而言,甚至還有一個工具THUNK.EXE被稱為“thunk編譯器”。
5. A person or activity scheduled in a thunklike manner. “It occurred to me the other day that I am rather accurately modeled by a thunk — I frequently need to be forced to completion.:” — paraphrased from a plan file.
Historical note: There are a couple of onomatopoeic myths circulating about the origin of this term. The most common is that it is the sound made by data hitting the stack; another holds that the sound is that of the data hitting an accumulator. Yet another suggests that it is the sound of the expression being unfrozen at argument-evaluation time. In fact, according to the inventors, it was coined after they realized (in the wee hours after hours of discussion) that the type of an argument in Algol-60 could be figured out in advance with a little compile-time thought, simplifying the evaluation machinery. In other words, it had ‘already been thought of’; thus it was christened a thunk, which is “the past tense of ‘think’ at two in the morning”.
closure
In programming languages, a closure is a function that refers to free variables in its lexical context.
在程式設計里,closure是一個函式。這個函式在其上下文中涉及到了釋放變數。
A closure is usually a function created by a program at run time. This is best demonstrated by a function that appears entirely within the body of another function. The nested, inner function must refer to local variables of the outer function. As the outer function executes, it creates a new instance of the inner function. If that inner function refers to some of the local variables of the outer function, a closure is formed. It consists of the function code and a reference to any variables in the outer function's scope that the closure needs.
Closures are commonly used in functional programming to defer calculation, to hide state, and as arguments to higher-order functions.
Several object-oriented techniques and language features simulate some features of closures. For example:
In [[C++]], programmers may define function objects by overloading operator(). These objects behave somewhat like functions in a functional programming language. They may be created at runtime and may contain state. However, they do not implicitly capture local variables as closures do. Two proposals to introduce C++ language support for closures (both proposals call them lambda functions) are being considered by the C++ Standards Committee [1], [2]. The main difference between these proposals is that one stores a copy of all the local variables in a closure by default, and another stores references to original variables. Both provide functionality to override the default behaviour. If some form of these proposals is accepted, one would be able to write
void foo(string myname) {
typedef vector names;
int y;
names n;
// ...
names::iterator i =
find_if(n.begin(), n.end(), <>(const string& s){return s != myname && s.size() > y;});
// i is now either n.end() or points to the first string in n
// which is not equal to myname and which length is greater than y
}
Java allows the programmer to define "anonymous classes" inside a method; an anonymous class may refer to names in lexically enclosing classes, or final variables in the lexically enclosing method.
class CalculationWindow extends JFrame {
private JButton btnSave;
...
public final calculateInSeparateThread(final URI uri) {
// The expression "new Runnable() { ... }" is an anonymous class.
Runnable runner = new Runnable() {
void run() {
// It can access final local variables:
calculate(uri);
// It can access private fields of the enclosing class:
btnSave.setEnabled(true);
}
};
new Thread(runner).start();
}
}
Subroutine:
A set of instructions that performs a specific task for a main routine, requiring direction back to the proper place in the main routine on completion of the task.
一組為主程式完成某項特定任務的指令集合,任務一旦完成需要跳轉回主程式合適的地方。
bletcherous:
Disgusting in design or function; esthetically unappealing. This word is seldom used of people. “This keyboard is bletcherous!” (Perhaps the keys don't work very well, or are misplaced.)
在設計或者是功能上的不滿;挑剔式的抱怨。這個詞人們通常都不怎么使用。如
“這個鍵盤有點bletcherous!”

相關詞條

熱門詞條

聯絡我們