简单了解malloc分配内存
直接看代码
#include <stdio.h> #include <malloc.h> int main() { int * p = (int *)malloc(1024 * 1024 * 1024); printf("分配后请查看内存"); getchar(); free(p); printf("释放后请查看那内存"); getchar(); return 0; }
按一下键执行free()
所以每次分配内存后一定要记得释放!
直接看代码
#include <stdio.h> #include <malloc.h> int main() { int * p = (int *)malloc(1024 * 1024 * 1024); printf("分配后请查看内存"); getchar(); free(p); printf("释放后请查看那内存"); getchar(); return 0; }
按一下键执行free()
所以每次分配内存后一定要记得释放!