VS2005 Debug版,dll /MTd,exe /MDd的潜在bug

少_游

关注

阅读 129

2022-07-27


VS2005 Debug版,dll /MTd,exe /MDd的潜在bug
dll中:

void DoStr(std::string& str)

{

str += "12345678901234";

}

exe中

void CtestexeDlg::OnBnClickedButton1()

{

std::string str = "1";

DoStr(str);

}


运行正常。修改str的初始值为"12",就崩溃了。
原因在于:
VS2005的std::string 当数据较短时,不从堆中分配内存;较长时,才从堆中分配内存。
跨组件(dll或exe)分配、释放内存只有当双方都是MD或MDd时才不崩溃。

精彩评论(0)

0 0 举报