i am totally new to malloc and i have to create a 3d array for a project.i read in description of malloc that you have to assign a +1 size for null ending byte..but i am not understanding where??? below is my block of code....
array = malloc(row*sizeof(int**));
for(i=0;i<row;i++)
{
array[i] = malloc(column*sizeof(int*));
if(array[i]==NULL)
{
printf("out of space");
return 1;
}
for(j=0;j<column;j++)
{
array[i][j] = malloc(3*sizeof(int));
if(array[i][j]==NULL)
{
printf("out of space");
return 1;
}
}
then i want access using array[1][1][1]...and so on....
if i use upto the column to assign some values..then in next if there are two fopen statement i am getting below error... i need fopen statements to read two files...
testImage: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted
But if i assign values to column-1 then the error is not there.....
Please help me here.....
Edited Details: This error i only get in ubuntu if i run it in unix i am not getting this error.... Sorry i will upload full code in 9 hours...(i dont have with me right now...sorry)...
yea i know it is poor emulation of 3D array but i just need it here... Let me define steps to you... First i define the array with above code. Then i assign values to each of the elements of the array...so i can manipulate it later...here if i assign values to every element using for loops in which if i include element array[row][column][1] = 23; Then after that if i open two files using fopen then the above error is generated..but if i open only one file using fopen then there is no problem....