【发布时间】:2021-07-19 19:22:33
【问题描述】:
我正在使用合并排序函数,它包含两个使用 malloc 函数的列表。为了提高性能,我需要通过分配单个缓冲区并设置 list1 来替换两个 malloc 调用
和list2 通过指向该缓冲区。这将 malloc/free 的调用次数减少了一半。
intType* list1 = (intType*)malloc(n1*sizeof(intType));
intType* list2 = (intType*)malloc(n2*sizeof(intType));
n1 = N /2;
和n2 = N -2;
N 是要排序的元素个数。
我尝试了不同的方法,但没有成功。有人可以帮忙吗?
【问题讨论】:
-
"and
n2 = N -2;":你的意思是“andn2 = N - n1;”吗? -
是的,我很抱歉。它的 n2 = N -n1;
标签: c performance optimization buffer