Let's say I have an integer array that contains junk and data. I wish to shift this array such that the data is at the start of the array.
Current:
[?, ?, ?, ?, 1, 1, 1, 1, 1]
---------- -------------
JUNK DATA
Desired:
[1, 1, 1, 1, 1, ?, ?, ?, ?]
------------- ----------
DATA JUNK
Is it safe to use memcpy to perform this shift?
memcpy(my_array, my_array + 4, 5)
I'm curious about the copy order of memcpy possibly corrupting the data shift.
Note: Before anyone asks, I'm working with legacy code. I think the true solution to my problem requires a circular buffer such that I don't have to shift data within an array.