Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Using native-arrays by pointer vs normal indexing in a burst-compiled job

Discussion in 'Scripting' started by kurroarashi, Mar 3, 2021.

  1. kurroarashi

    kurroarashi

    Joined:
    Dec 22, 2018
    Posts:
    28
    Hey guys,
    I've been really into using Unity Job System for multithreaded code and I had some doubts regarding array iteration.
    Is it in any way preferable to use pointers than the NativeArray struct's indexer?
    Using pointers means sometimes caching them as a struct field and it makes the struct size bigger by 8 bytes (on a 64-bit system), and I wonder if it actually gives any particular advantage.
     
  2. kurroarashi

    kurroarashi

    Joined:
    Dec 22, 2018
    Posts:
    28
    Or is it fine if one uses the foreach iterator?
     
  3. kurroarashi

    kurroarashi

    Joined:
    Dec 22, 2018
    Posts:
    28
    Solved - pointers are faster because of NativeContainer safety system, and can't use foreach in burst.
     
    Neiist likes this.