I have an array of structures in C as in (simplified):
typedef struct writeBuffer {
uint8_t *buffer;
struct someOtherStruct mySomeOtherStruct;
uint32_t length;
} writeBuffer;
Then I allocate an array of pointers to this structures as in:
int arrayLength = 20;
struct writeBuffer *myStructArray;
myStructArray = (struct writeBuffer *) malloc( arrayLength * sizeof(struct writerBuffer *));
So, effectively, I have an array of structures: Now, I have a function that writes to this array and a counter keeps track of the position in the array. Lets say arrayCount;
At some point, I try to flush to disk the elements written in the array of structs but am able to flush only n elements. Where n < arrayCount; So, I am left with arrayCount - n elements in the array.
In the next iteration, I want to start from where I left but in the mean time, more elements will be added to the array. In other words, after I have flushed n element in the array, I want to:
a. Retain the length of the array.
b. Delete the structs which were flushed to disked.
c. Reset the pointer now to the nth element as if it is the first element.
d. As I am keeping track separately of the number of elements left to be flushed, I do not care to zero out other elements in the array.
I can create a new array of structs and copy the ones left to be flushed to the beginning of the array but I am looking for something more efficient.