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 ScheduleByRef safe? (doesn't pin input struct)

Discussion in 'Entity Component System' started by kadd11, Jan 29, 2022.

  1. kadd11

    kadd11

    Joined:
    Mar 11, 2018
    Posts:
    33
    Is the ScheduleByRef extension for IJobParallelForDefer actually safe? It ends up doing an UnsafeUtility.AddressOf on the input struct reference, which isn't guaranteed to be on the stack or in pinned memory.
     
  2. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    258
    Unity currently uses the Boehm GC, which is non-compacting (managed objects will not be moved). So while it's a good idea to pin (so code is still safe when Unity eventually switches to CoreCLR), you won't encounter issues at the moment if you don't.
     
    apkdev likes this.
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Yes it is safe. When we expose unsafe API's we generally call them Unsafe***
     
    kadd11, Anthiese and apkdev like this.