棧內(nèi)存出了方法就會(huì)回收。
申請(qǐng)方式
alloca
堆內(nèi)存申請(qǐng)方式
malloc(biyte位內(nèi)存)
calloc(bitye,字節(jié))
申請(qǐng)40m 10241024=1m 110=10 10*4=40M
malloc(1024*1024*10*sizeof(int))
等于calloc(1024*1024,sizeof(int))
realloc(p,size);
在原來(lái)的地址分配易结,如果足夠沒(méi)有被其他占用那么直接連續(xù)從原來(lái)的p地址開(kāi)始分配 往后分配抱完,否則會(huì)新開(kāi)辟一塊內(nèi)存掰担。
感受內(nèi)存
#include<stdio.h>
void main() {
int i = 90;
printf("tes memory\n");
int b = 1024;
int kb = b * 1024;
int m = kb * 1024;//1024*1024*1024 個(gè)kb
int gb = m * 1; //2g 申請(qǐng)不了
int* p= malloc(gb);//申請(qǐng)不能超過(guò)1g,否則測(cè)試失敗了 返回nul
if (p != NULL) {
printf("我申請(qǐng)了內(nèi)存%d m 地址是%#x\n ,", gb /1024/1024, &p);
}
else {
printf("申請(qǐng)了內(nèi)存%d m 失敗碟摆,地址是%#x\n ,", gb /1024/1024,&p);
}
getchar();// 暫停
}
感受內(nèi)存的值
image.png