Lec5-C Memory Management
Contents
C Memory Management
malloc
|
|
|
|
不要踩坑!
An array name is not a variable. – K&R
when call &arr
, just get the address of the first element of the array
Linked List Example
|
|
Memory Locations
分配内存的方式
三个存储池
栈的映像图 LIFO
Memory Management
stack, static memory are easy to handle, but heap is a bit more complicated…
Implementing malloc and free
When Memory Goes Bad
- 不要轻易的访问栈区指针 / 地址
- 忘记
realloc
会移动数据
- 移动指针但是胡乱free or double free 🤯
Valgrind?
- Valgrind is a tool for detecting memory errors in C and C++ programs.