C
Chris
Hello all,
Not sure if this is off topic, if it is I apologise in advance.
Is it safe to use memmove() on an array of objects?
I create an array of Objects and I have a cursor to indicate how many of
those objects are in use. The one cravat is that the there are no unused
objects (gaps) between the first element of the array to the cursor.
When I remove an object I want to fill the gap by shifting the objects (on
the right) to the left by one. I currently use a for-loop to in which the
objects's operator=() is used.
I would like to replace the for-loop with something like this:
memmove(data+i, data+i+1, (sz-i-1) * sizeof(Object));
Where,
data is the array
i is the index of the object remove
sz is the number of used objects
I believe using memmove should be ok, but I thought it would be best to get
a 2nd opinion.
Thanks,
Not sure if this is off topic, if it is I apologise in advance.
Is it safe to use memmove() on an array of objects?
I create an array of Objects and I have a cursor to indicate how many of
those objects are in use. The one cravat is that the there are no unused
objects (gaps) between the first element of the array to the cursor.
When I remove an object I want to fill the gap by shifting the objects (on
the right) to the left by one. I currently use a for-loop to in which the
objects's operator=() is used.
I would like to replace the for-loop with something like this:
memmove(data+i, data+i+1, (sz-i-1) * sizeof(Object));
Where,
data is the array
i is the index of the object remove
sz is the number of used objects
I believe using memmove should be ok, but I thought it would be best to get
a 2nd opinion.
Thanks,