Some knowledge about why we need to new and delete everything in one module

Source: Internet
Author: User

Essence: Wrap functions to read/write things from another module.

Windows keep seperate heaps for debug and release-built DLLs and exes. so for example, calling a release DLL from a debug application EXE, any memory we allocate needs to be de-allocated by us in order for the heap management to be consistent. if everything is built release, it shoshould all come from the same heap and there shoshould be no inconsistency.

But problem happens when vc8 DLLs and vc9 EXE work together in case of memory allocation and deallocation. it's likely that vc8. vc9 DLLs and exes have the same issue. i. E ., VC8-built DLL and a VC9-built application may use different heaps, even for release builds. if so, the safest way is to deallocate and allocate memory always in one module.

And, going further, it's very likely that different module uses different heap, which means process default heap is always the first one to consider to use, but there are so sensitive possibility that a module use its custom heap instead of it. if failling into that case, how can another module call Delete directly to free the memory assigned in one module?

We can deallocate memory allocated in another module, but it will cause heap management inconsistency.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.