r**u 发帖数: 1567 | 1 Windows下,如果在一个DLL里malloc一个buffer,在另外DLL里free,有没有问题?每
个DLL有自己的heap,还是整个程序有一个heap?谢谢 |
c****e 发帖数: 1453 | 2 It's tricky,depends on the how c runtime is linked. If I remember correctly,
each dll with statically linked has its own heap. Otherwise they share when
the runtime version is the same. Exe and dll have different heap. It's
common issue to allocate in one heap while delete in another module which
causes memory corruption.
Search engine is your best friend on details. |
r**u 发帖数: 1567 | 3 多谢,这个C Runtime library是不是就相当于linux下的gcc的glibc?
我感觉windows的dll就相当于linux下的.so文件吧,linux下有我提到的这个内存分配
问题么?
correctly,
when
【在 c****e 的大作中提到】 : It's tricky,depends on the how c runtime is linked. If I remember correctly, : each dll with statically linked has its own heap. Otherwise they share when : the runtime version is the same. Exe and dll have different heap. It's : common issue to allocate in one heap while delete in another module which : causes memory corruption. : Search engine is your best friend on details.
|
b***i 发帖数: 3043 | 4 you can do it. Just some settings, to use same heap manager
【在 r**u 的大作中提到】 : Windows下,如果在一个DLL里malloc一个buffer,在另外DLL里free,有没有问题?每 : 个DLL有自己的heap,还是整个程序有一个heap?谢谢
|
x****u 发帖数: 44466 | 5 绝对不要做,永远只使用支持跨组件的内存分配函数。参考COM和Windows API的实现。
另外Linux下一样有类似问题,不过小屁孩动不动就把责任推给rebuild world。
【在 r**u 的大作中提到】 : Windows下,如果在一个DLL里malloc一个buffer,在另外DLL里free,有没有问题?每 : 个DLL有自己的heap,还是整个程序有一个heap?谢谢
|
x****u 发帖数: 44466 | 6 使用同一个DLL一样很微妙,因为DLL的入口是有CRT的函数的,可能会分配不同的数据
结构。
correctly,
when
【在 c****e 的大作中提到】 : It's tricky,depends on the how c runtime is linked. If I remember correctly, : each dll with statically linked has its own heap. Otherwise they share when : the runtime version is the same. Exe and dll have different heap. It's : common issue to allocate in one heap while delete in another module which : causes memory corruption. : Search engine is your best friend on details.
|