??????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?ɡ?