Effective C++ ????
???????????? ???????[ 2012/12/7 10:45:29 ] ????????
??????new??delete??????malloc??free
????malloc??free????????壩????????????????????????????????????????????????????
??????????????????????????10??string???????????????????malloc?????????new??
string *stringarray1 =
static_cast<string*>(malloc(10 * sizeof(string)));
string *stringarray2 = new string[10];
???????????stringarray1???????????????10??string???????????????????д?????Щ??????????????????????????????????????m4??m8?????????????????????????а?????????????????????仰???stringarray1???????????С?????stringarray2?????????????10???????????string????????飬?????????????κζ??string??????????á?
??????????????????ж?stringarray1???????????????????????????????????????????????????
free(stringarray1);
delete [] stringarray2;// ?μ?????5???????????????"[]"
????????free???????stringarray1??????棬????????string??????????????????????string????????????????????????????????棬????Щ??潫??????????????????stringarray2????delete??????????????????????????????????????????
???????new??delete?????????Ч???????????????????????????????????????
??????new??delete??malloc??free??????????????????????????new?????????????free????????????malloc?????????????delete???????????????????????“???????”????????????????????ι??????????????ι??????????????????????????????????????
????new/delete??malloc/free?????????????????Щ??????????????????????<string.h>??????и?strdup??????????????char*???????????俽????
char * strdup(const char *ps); // ????ps????????
????????Щ?????c??c++?????????strdup?汾????????????????malloc??????檔??????????Щ??????c++????????????strdup???????????strdup???????????free?????????????????????Щ?????????c++??дstrdup??????????????????new???????????????ú???delete?????????????????????????????????????????strdup????????????????????????????
????c++???????c????????????????????????????????????д???????malloc??freeд?????????c???????????á?????????Щ?????????????????free????????malloc????棬????/??????????malloc???????free?????棬?????????????????c++?????????malloc??free??д?????????malloc??????????free????????new???????????delete???????????????????????new??free??malloc??delete???????????????????鷳??
???????malloc??free???????????????????????????malloc/free??new/delete???????????????????????????????????????????????????????????new??delete?ɡ?
??????
???·???
??????????????????
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