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

     

     

  • 相关阅读:
    struts2 上传文件
    Struts2文件下载
    关于maven:调整你的maven的jdk版本为 xxxx
    倒计时显示
    [JSP] c:forEach 如何输出序号
    BaseServlet 继承 httpServlet
    验证码
    Javascript中Base64编码解码的使用实例
    五、javaScript基础&DOM(二)
    四、javaScript基础&DOM(一)
  • 原文地址:https://www.cnblogs.com/ecoflex/p/10204432.html
Copyright © 2011-2022 走看看