首页
社区
课程
招聘
经常见的thunk的解释
发表于: 2006-7-25 09:25 8111

经常见的thunk的解释

2006-7-25 09:25
8111
下面是定义:
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.
在电脑里,为了执行指令,需要在内存段地址和平坦地址之间进行转换。当16位应用程序在32位地址空间进行运行的时候,应用程序的16位段地址必须转化成32位平坦地址,这时候thunk是很容易见到的。另外,如果一个32位程序呼叫一个16位DLL,那么thunk就存在于相反的方向:从32位转变成16位。

相关的历史:
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<string> 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!”

此资料来源于网上。希望对大家有帮助

[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 2108
活跃值: (208)
能力值: (RANK:1260 )
在线值:
发帖
回帖
粉丝
2
最好能翻译,或加注释。

贵在持之以恒。有了wiki,这些就好归类管理了。
2006-7-25 14:36
0
雪    币: 47147
活跃值: (20450)
能力值: (RANK:350 )
在线值:
发帖
回帖
粉丝
3
最初由 arhat 发布
最好能翻译,或加注释。

贵在持之以恒。有了wiki,这些就好归类管理了。


wiki.pediy.com
可以登陆了,但还没搞好。
2006-7-25 14:40
0
雪    币: 6075
活跃值: (2236)
能力值: (RANK:1060 )
在线值:
发帖
回帖
粉丝
4
thunk的意思应是指“代码中的地址”

i.e.

mov eax, [401000h]
机器码
A1 00104000
地址为A的话A+1这个地址应该就是thunk

怎么翻译才能体现出这个意思呢?

我不知道,别问我。
2006-7-25 18:46
0
雪    币: 235
活跃值: (41)
能力值: ( LV9,RANK:170 )
在线值:
发帖
回帖
粉丝
5
最初由 forgot 发布
thunk的意思应是指“代码中的地址”

i.e.

mov eax, [401000h]
........


看意思好像是说寻址,并不仅仅指地址吧!
2006-7-25 20:13
0
游客
登录 | 注册 方可回帖
返回
//