C++杂记之Automatic、Static、Dynamic Storage and Memory Leaks

1、Automatic Storage :
【像我们定义的 int a; 啦啥的一些都是自动分配的,在function terminates 后会自己 expire】

2、Static Storage:
【会一直存在直到program execution 之后才会消失】
定义方式有两种:
<1>、define it externally, outside a function.(在函数外部)
<2>、加上static 关键字 (static double fee = 56.50;)

3、Dynamic Storage:
【new and delete operate provide a more flexible approach(灵活的方式) than automatic and static variable,但其实也让我们的内存管理变得更加complex,】

4、Stacks, Heaps, and Memory Leaks
在堆和栈中,如果你用new开辟了一个空间,但是却忘记用delete去释放掉,那么他的内存会一直占据着, In essence, you have no way to access the construct on the free store because the pointer to the memory that con-tains it is gone. You have now created a memory leak. Memory that has been leaked remains
unusable through the life of the program; it’s been allocated but can’t be deallocated. In extreme (though not uncommon) cases, memory leaks can be so severe that they use up all the memory available to the application, causing it to crash with an out-of-memory error. In addition, these leaks may negatively affect some operating systems or other applications run-ning in the same memory space, causing them, in turn, to fail.(哪位英语好的可以帮忙translation)【更严重会导致内存溢出】

【注:作为一个好的程序员,就要注意哦,it’s best to get into the habit of joining your new and delete operators immediately,】

猜你喜欢

转载自blog.csdn.net/qq_37982109/article/details/88687315