Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

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:
    2,661
  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!