我正在尝试制作这样的数组:
char tmp[4][32768];
//code
Run Code Online (Sandbox Code Playgroud)
这是在一个函数中,我发现使这个数组全局化将提高程序的速度(不幸的是我不能保持这样,因为函数在遇到某些数据时会递归调用自身)。我想让这个功能更快,但我读过它malloc可能很慢。那么,保持这样或这样做会更快吗?:
char** tmp;
tmp = malloc(4 * sizeof(char*));
tmp[0] = malloc(32768);
tmp[1] = malloc(32768);
tmp[2] = malloc(32768);
tmp[3] = malloc(32768);
//code
free(tmp[0]);
free(tmp[1]);
free(tmp[2]);
free(tmp[3]);
free(tmp);
Run Code Online (Sandbox Code Playgroud)