realloc??????????
?????chenyu ???????[ 2016/10/11 9:49:36 ] ????????realloc ???? ???
????realloc?????extern void *realloc(void *mem_address?? unsigned int newsize);
??????????? ??
?????????=??????????*??realloc??????????С??????????μ??С????
?????μ??С????С??????????????μ??СС???????С????????????????????????
????????
????#include <stdlib.h> ??Щ?????????#include <malloc.h>????TC2.0?п??????alloc.h????
????????
???????ж????????????????????????????У?????mem_address?????????????mem_address????????????????????newsize??????С???????????????????β???????·?????????????????????mem_address????????????????????????????????????free???????????·???????????????????????·???洢?????????
?????????
??????????·?????????????????????????????????NULL??
???????
????????治????????????free()??????????????
??????????
????1
????malloc??calloc??free??_alloca ??t???
????#include <stdio.h>
????#include <malloc.h>
????int main(int argc?? char* argv[])
????{
????int i;
????int *pn;
????pn = (int *)malloc(5*sizeof(int));
????for (i = 0; i < 5; i++) {
????pn[i] = i;
????printf("%d "??pn[i]);
????}
????printf("
");
????pn = (int *)realloc(pn?? 10*sizeof(int));
????for (i = 5; i < 10; i++) {
????pn[i] = i;
????}
????printf("all data
");
????for (i = 0; i < 10; i++) {
????printf("%d "??pn[i]);
????}
????printf("
");
????char *p?? *q;
????p = (char *)malloc(10);
????q = p;
????p = (char *)realloc(p??1000);
????printf("%x
"??p);
????printf("%x
"??q);
????char *m?? *n;
????m = (char *)malloc(10*sizeof(char));
????n = m;
????m = (char *)realloc(m??10*sizeof(char));
????printf("%x
"??m);
????printf("%x
"??n);
????}
???????н????
????realloc??????????#include<malloc.h> voidmain() { char*p??*q; p=(char*)malloc(10); q=p; p=(char*)realloc(q??20);//A?У????realloc????p?????????μ????????p?? //………………………… }????γ??????????????????q?????????????????????p????γ????????????????????е?A????????????????????????佫??п?????????????????′?С?????realloc????????????????????棬?????????????????????????????????????q?????????????????????????????!?????????q???????????????????????????з?????????????棬???????q?????в???????????????????????????????realloc?????????????????????????
??????????? ??????????void???????????ó??????????????????????????????????????
????????NULL?????????????С??????????????0???????????????NULL????????????“free??????”?????
????????NULL????????????????????????????????????С??????
??????????
?? 1. realloc???????????NULL
????2. realloc??????????????治??????????????????
????3. ??????????????滹????????????????realloc?????=????????+?????棬realloc????????????????; ????????????????????????????????realloc???????μ???棬???????????????????????????????????潫??free???realloc????????????
????4. ???size?0??Ч???????free()????????????????????????????????????????**a????a????realloc??????????????????????й???
????5. ?????realloc????????????????malloc()?? calloc()?? ??realloc()?????
????6.?????realloc?????????????????malloc??
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11