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.

  • 相关阅读:
    hello fetch
    git 基础命令
    拜占庭将军
    如何学习区块链
    简单的理解区块链技术
    使用AOP统一验签和校参
    为每个请求分配traceId的两种方式及父子线程本地变量传递
    监听kafka消息
    JVM OOM分析与调优
    JVM内存结构
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1288540.html
Copyright © 2011-2022 走看看