• stack(栈) and heap(堆)


    Heap is a large pool of memory used for dynamic allocation. When using new operator, to allocate the memory, the memory is assigned from heap. When a dynamically allocated variable is deleted, the memory is “returned” to the heap and can then be reassigned as future allocation requests are received.

    The heap has advantages and disadvantages:
    1) Allocated memory stays allocated until it is specifically deallocated (beware memory leaks).
    2) Dynamically allocated memory must be accessed through a pointer.
    3) Because the heap is a big pool of memory, large arrays, structures, or classes should be allocated here.

    As a structure, stack has a last-in, first-out (LIFO) property. The call stack is a fixed-size chunk of sequential memory addresses. The stack pointer keeps track of where the top of the stack currently is. Parameters, local variables, and function calls are pushed on stack.

    The stack has advantages and disadvantages:

    1) Memory allocated on the stack stays in scope as long as it is on the stack. It is destroyed when it is popped off the stack.
    2) All memory allocated on the stack is known at compile time. Consequently, this memory can be accessed directly through a variable.
    3) Because the stack is relatively small, it is generally not a good idea to do anything that eats up lots of stack space. This includes allocating large arrays, structures, and classes, as well as heavy recursion.

    reference: http://www.learncpp.com/cpp-tutorial/79-the-stack-and-the-heap/

  • 相关阅读:
    一月十三号学习日报
    一月十四号学习日报
    一月六号学习日报
    ARP欺骗
    一月十一号学习日报
    vscode文件名重叠
    vue : 无法加载文件 C:Users1111111AppDataRoaming pmvue.ps1,因为在此系统禁止运行脚本
    成绩录入和查询
    node搭建服务器
    class和id的区别
  • 原文地址:https://www.cnblogs.com/xispace/p/3393386.html
Copyright © 2020-2023  润新知