为什么DLL不能传出动态对象?

GuanXP 2003-07-28 06:08:22
简单的DLL函数void foo(vetor<int>& out)
如果在DLL内部放了对象进该vector,那么一定会在DLL外部的
该vector的析构函数处出错。对任何其他有DLL内部申请内存而
在DLL外部释放的情形,都会同样出错。

为什么会这样?难道DLL和载体不是在同一个堆上申请动态内存?

我使用的是VC6.0

...全文
20 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
GuanXP 2003-08-05
  • 打赏
  • 举报
回复
how can i judge whether a DLL has a static link to the run_time library?
Cline 2003-07-30
  • 打赏
  • 举报
回复
The _CrtIsValidHeapPointer function is used to ensure that a specific memory address is within the local heap. The “local” heap refers to the heap created and managed by a particular instance of the C run-time library. If a dynamically linked library (DLL) contains a static link to the run-time library, then it has its own instance of the run-time heap, and therefore its own heap, independent of the application’s local heap. When _DEBUG is not defined, calls to _CrtIsValidHeapPointer are removed during preprocessing.
Cline 2003-07-30
  • 打赏
  • 举报
回复
When applications or DLLs create private heaps, these live in the process space and are accessible process-wide. Any allocation of data made from a given heap should be freed for the same heap. (Allocation from one heap and free to another makes no sense.)

njypch 2003-07-30
  • 打赏
  • 举报
回复
难道DLL和载体不是在同一个堆上申请动态内存?
你说的不错.
joachern 2003-07-30
  • 打赏
  • 举报
回复
gz
铖邑 2003-07-28
  • 打赏
  • 举报
回复
好象是容器类,使用DLL有问题。

1,650

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 非技术类
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧