Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Disposing of NativeArray<ArchetypeChunk> with IJobParallelFor

Discussion in 'Data Oriented Technology Stack' started by MartijnGG, Aug 31, 2018.

  1. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    69
    I've been trying out the ArchetypeChunks and EntityArchetypeQuery to try and optimise some work by splitting the work per chunk of entities, instead of per X entities.

    Currently the psuedo code looks as following:

    Code (CSharp):
    1. var array = EntityManager.CreateArchetypeChunkArray(scoreQuery, Allocator.TempJob);
    2. var scoreType = GetArchetypeChunkComponentType<Score>();
    3.  
    4. var jobHandle = new ScoringJob
    5. {
    6.     Chunks = array,
    7.     ScoreType = scoreType,
    8. }.Schedule(array.Length, 1, inputDeps);
    9.  
    10. return jobHandle;
    This caused some issues with the allocated NativeArray, as it needs to be disposed of when this job has completed.
    How would I best Dispose of this, without calling jobHandle.Complete() followed by array.Dispose() of the chunks?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,049
    [DeallocateOnJobCompletion]
     
  3. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    69
    Using this attribute seems to cause it to deallocate once one of the parallel scheduled jobs is completed, instead of after the entire batch is done.

    Update: I'm not sure why, but when I try to reproduce the error now again to get the log for this topic.. it is no longer happening.
    I'm very sorry about that!
     
    Last edited: Aug 31, 2018
  4. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,380
    Will this be possible to do on NativeLists also? I tried and got a message that it was not supported.

    Lennart
     
  5. iam2bam

    iam2bam

    Joined:
    Mar 9, 2016
    Posts:
    36
    Had a hard time finding this... Maybe because the word Dispose is written everywhere else instead of deallocation.
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,029
    No, NativeList, NativeQueue, Native(Multi)HashMap hasn't [NativeContainerSupportsDeallocateOnJobCompletion] attribute, and thus not support [DeallocateOnJobCompletion] by design reasons, I think they not will be support this in future, but maybe I'm wrong and @Joachim_Ante says that :)
     
unityunity