我在与Scheme和类似地区相关的代码和文档中的很多地方都遇到了"thunk"这个词.我猜它是一个过程的通用名称,它有一个正式的参数.那是对的吗?如果是,那还有更多吗?如果没有,拜托?
例如.在SRFI 18中,在"程序"部分.
我有以下两个文件: -
single.cpp: -
#include <iostream>
#include <stdlib.h>
using namespace std;
unsigned long a=0;
class A {
public:
virtual int f() __attribute__ ((noinline)) { return a; }
};
class B : public A {
public:
virtual int f() __attribute__ ((noinline)) { return a; }
void g() __attribute__ ((noinline)) { return; }
};
int main() {
cin>>a;
A* obj;
if (a>3)
obj = new B();
else
obj = new A();
unsigned long result=0;
for (int i=0; i<65535; i++) {
for (int …
Run Code Online (Sandbox Code Playgroud) 在使用server.dll和client.exe的项目中,我dllexport
从服务器dll编辑了一个服务器符号,而不是将其 dllimport
编辑到客户端exe中.
仍然,应用程序链接,并启动,没有任何问题.是dllimport
不需要的,那么???
细节:
我有这个'服务器'DLL:
// server.h
#ifdef SERVER_EXPORTS
#define SERVER_API __declspec(dllexport)
#else
#define SERVER_API // =====> not using dllimport!
#endif
class SERVER_API CServer {
static long s;
public:
CServer();
};
// server.cpp
CServer::CServer(){}
long CServer::s;
Run Code Online (Sandbox Code Playgroud)
这个客户端可执行文件
#include <server.h>
int main() {
CServer s;
}
Run Code Online (Sandbox Code Playgroud)
服务器命令行:
cl.exe /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL"
/D "SERVER_EXPORTS" /D "_UNICODE" /D "UNICODE" /D "_WINDLL"
/Gm /EHsc /RTC1 /MDd /Yu"stdafx.h"
/Fp"Debug\server.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb"
/W3 /nologo …
Run Code Online (Sandbox Code Playgroud) 尝试跟踪Xcode Instruments中的内存泄漏时,我经常在Stack Trance中看到以下行:
thunk for @escaping @callee_guaranteed () -> ()
Run Code Online (Sandbox Code Playgroud)
这是什么意思?在这种情况下,我什至无法翻译粗俗的单词,更不用说它的技术含义了。完整的堆栈跟踪如下所示:
0 libsystem_malloc.dylib calloc
1 libobjc.A.dylib weak_resize(weak_table_t*, unsigned long)
2 libobjc.A.dylib weak_register_no_lock
3 libobjc.A.dylib objc_storeWeak
4 SpriteKit -[SKNode(setParent) setParent:]
5 SpriteKit -[SKNode insertChild:atIndex:]
6 SpriteKit -[SKNode addChild:]
7 IOSTest PieceNode.setup() /.../PieceNode.swift:66
8 IOSTest LabeledPieceNode.setup() /.../PieceNode.swift:86
9 IOSTest closure #1 in closure #1 in MaskedRectBoardNodeController.maskedRectBoard(_:didFill:with:alongGravity:) /.../MaskedRectBoardNodeController.swift:48
10 IOSTest thunk for @escaping @callee_guaranteed () -> () /.../<compiler-generated>:0
11 libdispatch.dylib _dispatch_call_block_and_release
12 libdispatch.dylib _dispatch_client_callout
13 libdispatch.dylib _dispatch_main_queue_callback_4CF$VARIANT$mp
14 CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
15 …
Run Code Online (Sandbox Code Playgroud) Can someone explain to me what a Thunk is?
and an ATL Thunk?
I know a thunk has something to do with the vtbl and execution of code to find the right function pointer. Am I right?
想象这个假的程序:
void foo ( void )
{
// anything
}
int main ()
{
foo ();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当使用Visual Studio在调试模式下编译时,编译器会构建某种"函数映射",或者调用它.
因此,当您在调试器中跟踪foo(),或者只是尝试通过&foo检索函数的偏移量时,您会发现自己处于jmp的"列表"中,当您再次关注它们时会引导您进入实际函数身体.
我的问题是:是否有可能为单个选择函数禁用它,以便&foo将地址返回给函数体,而不是jmp.当然没有禁用调试模式.
如果没有,哪个标志启用/禁用整个程序?
提前致谢 !
编辑用户SigTerm:
c++ ×4
assembly ×1
declspec ×1
dllimport ×1
inheritance ×1
instruments ×1
memory-leaks ×1
performance ×1
scheme ×1
syntax ×1
thunk ×1
xcode ×1