zoukankan      html  css  js  c++  java
  • New/delete VS malloc/free

    REFER:SO

    中文社区见到的答案,不提也罢

    new/delete

    • Allocate/release memory
      1. Memory allocated from 'Free Store'
      2. Returns a fully typed pointer.
      3. new (standard version) never returns a NULL (will throw on failure)
      4. Are called with Type-ID (compiler calculates the size)
      5. Has a version explicitly to handle arrays.
      6. Reallocating (to get more space) not handled intuitively (because of copy constructor).
      7. Whether they call malloc/free is implementation defined.
      8. Can add a new memory allocator to deal with low memory (set_new_handler)
      9. operator new/delete can be overridden legally
      10. constructor/destructor used to initialize/destroy the object

    malloc/free

    • Allocates/release memory
      1. Memory allocated from 'Heap'
      2. Returns a void*
      3. Returns NULL on failure
      4. Must specify the size required in bytes.
      5. Allocating array requires manual calculation of space.
      6. Reallocating larger chunk of memory simple (No copy constructor to worry about)
      7. They will NOT call new/delete
      8. No way to splice user code into the allocation sequence to help with low memory.
      9. malloc/free can NOT be overridden legally
  • 相关阅读:
    jmeter录制
    Jmeter之逻辑控制器
    Jmeter关联
    Jmeter之HTTP请求默认值
    shell一文入门通
    Linux系统编程——基础命令总结
    前端专业方向的尽头
    锤子,技术与交互体验细节
    学习汇总 2019-12-2
    不容错过的 Babel7 知识
  • 原文地址:https://www.cnblogs.com/invisible/p/3008700.html
Copyright © 2011-2022 走看看