1. 程式人生 > >VC動態陣列實現

VC動態陣列實現

//C-style character string implementation
const char *pc="a very long literal string";
const size_t len=strlen(pc +1); //space to allocate
//performance test on string allocation and copy
for(size_t ix=0;ix!=1000000;++ix){
char *pc2=new char[len+1]; //allocate the space
strcpy(pc2,pc);             //do the copy
if(strcmp(pc2,pc))         //use the nuw string
   ; //do nothing
delete[] pc2;              //free the memory
}