Hello,
Could you tell me how to build a grid of data that can be update very fast.
For instance I would like to cut the top of the grid and move up all the rest
of the data. I do not use memcpy() because it wast time.
I give bellow a sample of program and it gives me an "segmentation fault".
What is wrong in my code ?
Thanks.
Code:
// The goal of this program is to remove
// the head of an int array structure. At first the structure have 10 lines of int
// , at end it must have 9 lines.
//The old location [0] will be filled by value of [1] and so on.
// This works under windows/Watcom compiler not for linux GCC/GLIBC. Why ?
#include <stdio.h>
#include <stdlib.h>
void **data;
void *temp;
int main(void)
{
data = (void**) malloc(10);
data[0]= (int*)malloc(sizeof(int));
data[1]= (int*)malloc(sizeof(int));
//****************** Set data ***********
data[0]=100; data[1]=200;
//*********** Cut the head of array *****
temp=data[1];
data[0]= (int*) realloc(temp, sizeof(int));
printf("%d\n", data[0]); // I expect to obtain 200 here as result not 100.
return(0);
}