I'm writing a class member function to remove a row from a (m x n) matrix. The memory model for the matrix (from a standard linear algebra library) is guaranteed to be a contiguous block such that the (i, j)th element maps to the (i * n + j)th element of that memory block.
I'd like to use ::memcpy
for clarity and performance reasons. (The alternative ways using for
loops are cumbersome.) But I need some reassurance.
In general, the destination location overlaps the source location since, if I'm deleting row r, I'd use (dropping any casts for clarity),
::memcpy(r * n, (r + 1) * n, bigger than n in general)
If ::memcpy
is guaranteed to copy from the start of the block, then this will be fine. But, does the standard guarantee this? I can't see why it would and suspect the behaviour of such code is undefined.