NativeArray is a Struct type. Structs are passed by value (copied) in C#. But I wonder if Native structs are doing the same.
This example code:
public static IEnumerable<int> GetAllHits(NativeArray<int> array...
The array passed can’t have any “ref” or “in” or “out” attributes for IEnumerable methods. If I pass it like that, will it be copied or passed by reference?
If I pass it like that, will it be copied or passed by reference?
Struct will be passed by value (copied), but data it’s points to won’t be copied or anything like that.
Maybe it will bring you some clarity here when you realize that this structure is very simple at heart. When you look into it’s source code and remove all the thread-safety fluff - it comes down to just these few lines:
unsafe struct NativeArray<T> where T : struct
{
void* m_Buffer;
int m_Length;
int m_MinIndex;
int m_MaxIndex;
}
Conclusion: NativeArray is a pointer :T