堆空间内存控制
- malloc \ free C语言模式内存申请和释放
- new \ delete C++模式内存申请和释放
- new[] \ delete [] C++模式数组内存申请和释放
//malloc \ free
int size = sizeof(int) * 10;
int *p1 = (int *)malloc(size);
memset(p1, 0, size);
//memset是数据清理函数,将从p1地址开始,长度为size的字节,全部置为第二个参数,也就是0;
free(p1);
//new \ delete
int *p2 = new int(); //int后带(),会对数据初始化为0,
delete p2;
//new[] \ delete []
int* p3 = new int[3]();
p3[0] = 1;
delete[] p3;