今天来讲一讲memory management in C
在ubc cpsc213的课程中介绍了三种ways:
1. dangling pointer
2. memory leak
3. reference counting
首先在介绍这三种方法之前,先来讲一讲dynamic malloc in C
eg. int a = malloc(sizeof(int);*
definition:malloc return block of bytes with no associated type or initialization 也就是一个void pointer。这个例子它会在heap上面随机寻找一个4个bytes大小的memory,标记为 in use from vacant,并且让variable a指向这块地址。
接着我们再来看看static array和dynamic array的区别: