Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Is UnsafeUtility.MemMove guaranteed to support overlapping memory blocks?

Discussion in 'Entity Component System' started by Jonas_DM_, Nov 20, 2022.

  1. Jonas_DM_

    Jonas_DM_

    Joined:
    Feb 28, 2019
    Posts:
    22
    I'm curious if the implementation of UnsafeUtility.MemMove is guaranteed on every platform to support overlapping memory blocks. (like memmove in C).

    My use case is quite unique, but I basically want to resize a container. Before resizing I need to move certain scattered data (from inside the container) to the front of the container.
    I'd prefer if I could do this in-place without a temporary buffer.
    This in-place memory moving could have sourcePtr being between desinationPtr and
    destinationPtr+moveAmount. (which is what i mean with overlapping memory blocks).

    I did a few tests on my windows pc in editor & it did support it. (sourcePtr==destinationPtr, sourcePtr inside destination memory block & destinationPtr inside source memory block)
    But can I assume MemMove on every platform supports overlapping memory blocks?
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,869
  3. Jonas_DM_

    Jonas_DM_

    Joined:
    Feb 28, 2019
    Posts:
    22
    Ok, now I feel silly. Didn't know these unsafe methods were documented.
    Thanks!