Search Unity

NativeArray aligned in memory?

Discussion in 'Entity Component System' started by AlexandrBuryakov, Oct 9, 2019.

  1. AlexandrBuryakov

    AlexandrBuryakov

    Joined:
    May 30, 2018
    Posts:
    31
    Hello!
    1) NativeArray aligned in memory?
    2) If you process a loop in blocks of 64 bytes, will the blocks fall entirely into the cache line?
    3) Is there a risk of an array offset and 64 bytes will occupy two different cache lines?
    4) Does it make sense to optimize in this way? (the busiest cycle)
    Thank!
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    Are you asking if NativeArrays are allocated with their starting points sitting on the start of a cache line?
    4) The reinterpretLoad/Store in 2019.3 and upcoming intrinsics will make this meaningful if you are getting that low-level.
     
  3. AlexandrBuryakov

    AlexandrBuryakov

    Joined:
    May 30, 2018
    Posts:
    31
    Yes.
    1) Probably the location of the starting points of the arrays in memory will be more universal at addresses that are multiples of 128 bytes. So the data will be aligned 32, 64, 128 byte cache lines. I just want to know if this is being done now or will it be later? (To plan the code now)
    2) Is there a way to find out the memory address of the beginning of the NativeArray array?
    It seems such simple things, but how to do it is not clear ...
     
    Last edited: Oct 10, 2019
  4. SlavicBrat

    SlavicBrat

    Joined:
    Jul 1, 2014
    Posts:
    3
    Maybe you can try this? https://docs.unity3d.com/ScriptRefe...fe.NativeArrayUnsafeUtility.GetUnsafePtr.html

    Haven't tested it so don't know.
     
  5. AlexandrBuryakov

    AlexandrBuryakov

    Joined:
    May 30, 2018
    Posts:
    31