zoukankan      html  css  js  c++  java
  • Some knowledge about why we need to new and delete everything in one module

    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 should all come from the same heap and there should 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 vs. 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 many 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.

  • 相关阅读:
    jQuery 语法
    jQuery 简介
    把数据存储到 XML 文件
    XML 注意事项
    XML DOM (Document Object Model) 定义了访问和操作 XML 文档的标准方法。
    通过 PHP 生成 XML
    XML 命名空间(XML Namespaces)
    XML to HTML
    XMLHttpRequest 对象
    使用 XSLT 显示 XML
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1288540.html
Copyright © 2011-2022 走看看