Search Unity

Why can't we tag NativeList and NativeHashMap with [DeallocateOnJobCompletion]?

Discussion in 'Data Oriented Technology Stack' started by Abbrew, Mar 28, 2019.

  1. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    149
    Someone discovered that NativeHashMap is implemented using 3 NativeArrays which can be automatically deallocated inside a job. Likewise NativeList might be implemented as a wrapper for NativeArray with resizing capabilities. Is there a reason why despite this those two data structures cannot be deallocated inside a job? Without the ability to do so, we have to implement some strange workarounds to dispose of NativeLists and NativeHashMaps without breaking job dependency chains
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    355
    I'm bumping this since i'd also like to know why, and it's the only question i found about it.
    The other problem i have with manually disposing nativehashmaps is that [DeallocateOnJobCompletion] deallocates the memory from that worker thread (to my knowledge), while if we have to manually call .Dispose() outside of jobs, it ends up taking up time on the mainthread, thus potentially introducing spikes. Or am i missing something?
     
  3. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    436
    Dispose(JobHandle inputDeps) was added relatively recently to all the containers and solves that problem.
     
  4. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    489
    Does this mean that it can be tagged now?
     
  5. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    210
    Mmmmm dont think so. I think you need to use the dispose passing the jobhandle afterwards in the scheduling...

    However, it'd be nice to be qble to just tag it. Unsure of the performance impact/ dev yime cost for unity though to implement that.