Dll中开辟内存在外的释放问题

     昨天遇到一个很奇怪的问题,引用一个DLL,里面有内存开辟的操作,后来在外面释放的时候总出问题,查了查资料,后来找到了解决方案!其中引起这个问题的原因主要是跨module的内存开辟和释放可能不在同一个runtime libary,后来把DLL和EXE都设置为MTD后就好了,在这里再用别人的一篇文章(很有用),这篇文章主要说明在dll中开辟内存要和项目在同一个运行时库上面,那样就不会导致内存的泄露,而且在同一个运行时库上面让程序员更轻松的在项目中对dll中的内存操作:

 

Allocating and freeing memory across module boundaries

I'm sure it's been drilled into your head by now that you have to free memory with the same allocator that allocated it. LocalAlloc matches LocalFree, GlobalAlloc matches GlobalFree, new[] matches delete[]. But this rule goes deeper.

If you have a function that allocates and returns some data, the caller must know how to free that memory. You have a variety of ways of accomplishing this. One is to state explicitly how the memory should be freed. For example,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值