char* buffer = (char*) malloc(tag_name_len + tag_attributes_len + other_attributes_len + 10); assert(buffer); strcpy(buffer, "<"); strcat(buffer, tag_name); if(tag_attributes_len > 0 && bWriteUserAttributes) { strcat(buffer, " "); strcat(buffer, tag_attributes); } if(other_attributes_len) { strcat(buffer, " "); strcat(buffer, other_attributes); } strcat(buffer, ">"); //... free(buffer); 我写完这段代码突然就后悔了,每次strcat内部都要对buffer取文本长度吧,而buffer内的文本是逐渐变长的。 当然优化这段代码有多种方法,我想说的是,char*这种数据结构太原始了。