Search Unity

What Collections types support parallell writing?

Discussion in 'Entity Component System' started by rogerdv, Sep 30, 2019.

  1. rogerdv

    rogerdv

    Joined:
    Jul 16, 2012
    Posts:
    90
    Is there some that let me safely write values from different jobs?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Anything with AsParallellWriter

    NativeQueue
    Native[Multi]HashMap
    NativeStream
     
  3. rogerdv

    rogerdv

    Joined:
    Jul 16, 2012
    Posts:
    90
    Well, my knowledge of C++ STL is a bit rusty, but NativeMultiHashMap is like an array where indexes can be repeated? Sounds like the kind of data structure I need right now.
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    NativeHashMap : Dictionary<Key, Value>
    NativeMultiHashMap : Dictionary<Key, List<Value>>
     
  5. rogerdv

    rogerdv

    Joined:
    Jul 16, 2012
    Posts:
    90
    NativeHash is like a NativeDictionary?
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    NativeHashMap<TKey, TValue> is a replacement for Dictionary<TKey, TValue>
     
  7. Jyskal

    Jyskal

    Joined:
    Dec 4, 2014
    Posts:
    28
    Indexes are not repeat but you can store multiple values under the same index in a List. TryGetFirstValue() and TryGetNextValue() should be used.
     
  8. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,684
    Technically they repeat. If you look at source code (TryGetFirstValueAtomic\TryGetNextValueAtomic) it has pointer to keys array and next iteration of TryGetNextValueAtomic "grows" entryIdx from next pointer, thus in keys array key can repeat, and this is why you get duplicates if you call GetKeyArray on NMHM.