gpt4 book ai didi

c - 我正在尝试释放结构数组但得到 free() : invalid next size (fast): 0x0000000000afa010

转载 作者:太空宇宙 更新时间:2023-11-04 08:07:04 24 4
gpt4 key购买 nike

struct cacheline
{
int x[16];
};
struct cacheline *block = malloc(sizeof(struct cacheline) *size); //malloc for array of stucts
write_start = clock();
for (k=0;k<=1000;k=k+1){
for (i=1;i<=size;i=i+1){
for(j=0;j<16;j=j+1){
block[i].x[j] = j+1; ///some operation
}
}
}
write_stop = clock();
Elapsed_write_time = (double)(write_stop - write_start)/1000 * 16;
printf("Elapsed time: %f\n",Elapsed_write_time);
free(block); //free the araray of structs

我正在尝试释放结构数组,但出现以下错误。

最佳答案

您写到了数组末尾。最后一个元素是 block[999] 但您的代码也会写入 block[1000]

关于c - 我正在尝试释放结构数组但得到 free() : invalid next size (fast): 0x0000000000afa010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42104236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com