Search Unity

NativeArray indexing operator not returning by ref

Discussion in 'Data Oriented Technology Stack' started by sebas77, Aug 14, 2019.

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    862
    is there an alternative workaround to this problem? I need to change single fields of the structs held by the NativeArray and I can't do that.
     
  2. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    862
    NVM I forgot about the UnsafeUtilityEx in the collection package, however it seems a bit hackish
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,559
    Struggling to understand your problem.

    I assume it is

    Array.Value =x // doesn't work

    But the solution has always been

    var element = Array
    element.Value = x
    Array = element
     
  4. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    862
    doing what you said could comprise the performance in a cache friendly performance critical scenario.

    more info: Nowadays CPUs can read a continuous block of data up to 64 bytes in one single memory access from the L1 cache (which takes around 4 cycles of clock). If the struct is more than 64 bytes you can have a good hit in performance.
     
  5. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    371
    Burst usually optimizes that away and just modifies the array in place.
     
  6. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    862
    hmmmmmmm that would make sense although it seems quite an advanced analysis. I'll check it.