Search Unity

Is there a list or container that can add items in parallel?

Discussion in 'Entity Component System' started by davenirline, May 25, 2021.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    982
    I thought that this should be doable since EntityCommandBuffer.ParallelWriter can do it by using a sort key. I want the same functionality for a container.
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,770
    What you mean by items? You mean ECS components?
    There is Dynamic Buffer, to which you can set values in parallel.
    I don't know what you exactly asking for.
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    How are you adding items safely to a Dynamic Buffer in parallel o_O

    Nearly every container has a parallel writer

    NativeList<T>.ParallelWriter
    NativeStream.ParallelWriter
    NativeQueue<T>.ParallelWriter

    etc

    The limitation is just the capacity can't be increased in parallel, you have to pre-compute it or ensure it's large enough to put all your elements.
     
    davenirline likes this.
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,770
    Rather add in parallel, I first set (i. E. resizeunitialised) the size of dynamic buffer in separate job. That's providing we know the required size of the buffer before hand. Or calculate needed size.

    Then in next job, in parallel I can assign values to the buffer, assuming knowing appropriate indexes (no race conditions) , or run it thrugh IJobParralelFor as an example.
     
  5. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    982
    Oh, I didn't know that. That helps a lot.