小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

DLL的災(zāi)難

 Fredanf 2013-03-06

DLL的災(zāi)難---DEBUG與RELEASE版本不能交叉調(diào)用

讓我們先看一段引文,再來進(jìn)行心靈的探索:

If you have an EXE and a DLL.

When your exe APP was built Debug Mode, your Dll must be Debug mode. 

When your exe APP was built Release Mode, your Dll must be Release mode. 

If exe is Release Mode and Dll is Debug Mode, Error. 

If exe is Debug Mode and Dll is Release Mode, Error.

-------------------------------- Why? --------------------------------

Looks like you have a problem with memory allocation.

When an application is built in debug mode it does not allocate memory from the same heap as it does in release mode.(have a look to the definition of new and delete operator, and also to malloc (in afxmem.h ? (not sure just grep it))

Thus, when you get some memory from your debug app and give this memory to your release dll for processing and FREEING,you get an error since the realase dll tries to free it from the wrong heap. So always use your app and dll in the same mode. 

At least, do not try to free memory allocation in one mode in the other mode.


現(xiàn)在,我們來概括一個(gè)結(jié)論:

之所以,Dll與Exe之間進(jìn)行Release與Debug的交叉調(diào)用會(huì)出現(xiàn)錯(cuò)誤,一個(gè)非常重要的原因,可能是由于Debug下與Release下,模塊的導(dǎo)入地址是不一樣的,即使你取消所有的優(yōu)化,也許也并不能改變這樣的結(jié)局。 從而對(duì)于一個(gè)在Exe(假如是Release版本)中生成的對(duì)象(比如一個(gè)靜態(tài)的全局?jǐn)?shù)組),與一個(gè)在Dll中生成的對(duì)象可能會(huì)位于完全不同的內(nèi)存區(qū)域,從而對(duì)那些借助于對(duì)靜態(tài)指針的值進(jìn)行判斷的類(比如CString)跨模塊調(diào)用的時(shí)候,一旦出現(xiàn)判斷,將會(huì)出現(xiàn)嚴(yán)重的邏輯錯(cuò)誤,從而使一塊本不該被釋放的內(nèi)存被釋放,從而引發(fā)運(yùn)行時(shí)的錯(cuò)誤。

解決交叉調(diào)用的最簡單,最合理的方法就是: debug調(diào)用debug版,release調(diào)用release版,這也許就是模塊化中的一個(gè)瑕疵吧。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多