在尾部调用之后除去栈结构的方法称为尾部调用优化。
The idea of removing stack frames after tail-calls is called tail-call optimization.
可见,尾部调用使用了更多一些指令,但是它们可以节省相当多内存。
As you can see, tail-calls take a few more instructions, but they can save quite a bit of memory. There are a few restrictions for using them.
好像一旦控制权传递给了尾部调用的函数,栈中就再也没有有用的内容了。
It seems that once control is passed to the tail-called function, nothing in the stack is useful anymore.
惟一的问题在于,现在只有非常少的编译器实现了尾部调用优化。
The only problem is that right now very few compilers implement tail-call optimizations.
这里是为那些真正热衷底层编程的人准备的一个优化尾部调用的汇编语言模板。
For those who actually like to mess with the low-level stuff, here is an assembly language template for an optimized tail-call.
可见,要使调用成为真正的尾部调用,在尾部调用函数返回之前,对其结果不能执行任何其他操作。
As you can see in order for the call to be a true tail-call, no other operation can be performed on the result of the tail-called function before it is passed back.
这意味着我们必须手工重新编写栈来仿造一个返回地址,以使得尾部调用的函数能直接返回到调用它的函数。
This means that we have to manually rewrite the stack to fake a return address so that the tail-called function will return directly to our parent.
再也不需要活动记录(activation record),所以我们将删掉它,并将尾部调用的函数重定向返回到调用我们的函数。
The activation record isn't needed anymore, so we are going to cut it out and redirect the tail-called function back to the function that called us.
例如,前面描述的 print_report_i函数在GCC 3.4 中使用-O2 进行尾部调用优化编译,因此运行时使用的栈的大小是固定的,而不是线性增长的。
For example, the print_report_i function described earlier compiled with tail-call optimization using -O2 on GCC 3.4 and therefore runs with a stack-size that is constant, not growing linearly.
函数在尾部被调用之后,还需要使用哪个本地变量?
After the function in tail position is called which of our local variables will be in use?
也就是说,如果你向一个数据的尾部之后写数据,程序不会注意到,直到下个malloc或者free调用。
That is, if you write beyond an array's end, it won't be noticed until the next malloc or free call.
使得链中的下一个过滤器被调用,如果该调用过滤器已是链中的最后一个过滤器,那么使得链尾部的资源被调用。
Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked.
使得链中的下一个过滤器被调用,如果该调用过滤器已是链中的最后一个过滤器, 那么使得链尾部的资源被调用。
ServletException Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked.
Filter使用FilterChain调用链中的下一个过滤器,如果调用过滤器是链中的最后一个过滤器,调用链尾部的资源。
Filters use the FilterChain to invoke the next filter in the chain, or if the calling filter is the last filter in the chain, to invoke the resource at the end of the chain.
Filter使用FilterChain调用链中的下一个过滤器,如果调用过滤器是链中的最后一个过滤器,调用链尾部的资源。
Filters use the FilterChain to invoke the next filter in the chain, or if the calling filter is the last filter in the chain, to invoke the resource at the end of the chain.
应用推荐