DLL解惑一篇

1. Does a DLL have it's own stack and heap?

It's thead who has stack rather than DLL. Each thread which enters DLL's code has its own usual stack which it always has. Heap is per process but you can add to the default process heap your own, private one.

2. Can a process call multiple instances of a DLL?

No, LoadLibrary API won't load it two times.

3. What I really want to know is whether multiple instances of a DLL share the same static variables, or whether they have their own static variable space.

This depends on how the DLL was built. If it was built using "staticly link to run-time library" option (which means code from C run-time library was embedded into DLL) then DLL will have it's own static variable space. Otherwise ( C run-time library was linked dynamically which means at run-time C run-time code is executed from separate C run-time DLL) no.

最后一部分写的是,DLL编译时(VC)选择Multithreaded DLL则DLL自身动态链接运行时库,而如果选择Multithreaded则DLL自身静态包含了运行时库。这从生成的DLL大小中也可看出端倪。前者共享static variable space,这个很重要。而如果使用后者则在exe程序link时很可能报符号重定义。

posted @ 2006-09-05 15:27  eygneph  阅读(245)  评论(0编辑  收藏  举报