pretty code

2020年5月27日 星期三

Windows DLL 相關名詞備忘

很久沒有寫 DLL 了,剛吃飯時跟同事聊到 Windows DLL,有些討論雖然意思對,但名詞錯,顯得有些不專業,趕快 Google 惡補一下。


2020/05/28 更新

早上趁著拍片時翻了一下《程式設計師的自我修養:連結、載入、程式庫》,因為太趕,沒有看到作者有特別著墨這些名詞。

圖片的中文翻譯有點差,還是來看看英文版好了。


2020/06/04 更新

A dynamic-link library (DLL) is a module that contains functions and data that can be used by another module (application or DLL).

DLL 的函數有分內部及外部 (定義給其他 module) 用。
因為 DLL 內容會被載入到呼叫者的記憶體空間,故那些內部使用的函數是無法保護的。
所有的呼叫者會共享 DLL Code,故可以減少系統記憶體使用。

Types of Dynamic Linking

1. In load-time dynamic linking
    呼叫者用起來就像自己的 local functions,故呼叫者在編譯程式時,要拿到 .h 和 .lib 兩個檔案。

2. In run-time dynamic linking 
    呼叫者使用 LoadLibrary 和 GetProcAddress 來載入 DLL 以及使用函數 (function pointers),故只需要 DLL 檔。

DLL 比 static linking 優秀的地方

只要 DLL 的 function arguments, calling conventions, return values 沒有改變,呼叫者不需要重新編譯 (In load-time dynamic linking 也是嗎?)

沒有留言: