zoukankan      html  css  js  c++  java
  • Modern C++ Course [Lecture 7] {Pointers, const with pointers, Stack and Heap, Memory leaks, Dangling pointers}

    https://en.cppreference.com/w/cpp/language/range-for

     

     

     

    every object has a pointer to itsleft.

     

     

    stack operations are very quick

    it's computationally expensive to search variables in a stack, when the scopes and functions are very large. 

     So, keep your scope and func small.

    An example: 

     

    then we create a new scope

    end of scope, and the scope does 2x pop, and remove everything from the first parenthesis

     (beauty of C++ is that it manages its memory based on scopes)

    the problem now is that prt loses its value

     

    heap is much more complicated than stack

    heap usually has much larger volume than stack

    memory management is not automatically done.

    ?????

     

     

     

     eg, first we assign ptr 1 and 2 to two different velues

    then we assign ptr 2 to the address of the upper variable

    the system thinks we might use the bottom variable, but we have lost access to it, and we can't remove it by delete some_ptr

    we tried to delete some memory twice.

     

    in line 10, every time we allocate a new data, system creates a new ptr to it. we can't use line 16 to free the memory

     

     

     

    this is the way before c++11

     

     

  • 相关阅读:
    switch多分枝语句
    自动扫描判断数组奇偶 直接在控制台输入
    if else语句
    1231作业
    字符集和字符编码
    12.28作业
    置顶广告
    图片库
    js实现隔行换色及其鼠标滑过变色
    【转载】display:inline-block兼容ie6/7的写法
  • 原文地址:https://www.cnblogs.com/ecoflex/p/10204432.html
Copyright © 2011-2022 走看看