I am using a char * array to make a buffer to move information from multiple mapping threads to a reducing thread. I need to make the array circular, however, i keep getting segmentation faults when the array runs out of room. How do I make the array circular? I currently have
for(j = 0; j < i; j++){
int next = mr->nextIndex + j;
if(next > 1023){
next = 0;
}
mr->buffer[next] = temp[j];
}
The array is set up as,
new_mr->buffer = malloc(sizeof(char *) * MR_BUFFER_SIZE);
with the macro being 1024. Any help is appreciated.
temp is
char *temp = malloc(sizeof(char *));
and it gets its value from
memcpy(temp, kv, i);
and kv is passed into the function from the main.