#NativeStream correct usage

1 messages · Page 1 of 1 (latest)

jolly vine
#

My stream is:
NativeStream stream = new NativeStream(SystemInfo.ProcessorCount, Allocator.TempJob)

So it has as many buffers as the number of threads, so I can write on each buffer depending on which thread I am when I'm on a huge IJobParallelFor, which is apparently safe.
I just want to be able to concurrently append all the values I generate, but with the safety of writing only from one thread to one buffer.

I pass the NativeStream to a job with AsWriter() . Then I call BeginForEachIndex(threadIndex), then stream.Write(value) and then EndForEachIndex() .

Well, seems like the ThreadIndex must be 0 only now. I get an ArgumentException: Index X is out of restricted IJobParallelFor range [0..0]

I saw that when you create a Writer, it resets the internal counters! But to the MinValue... I wonder what I'm doing wrong.

` internal Writer(ref NativeStream stream)
{
m_Writer = stream.m_Stream.AsWriter();

#if ENABLE_UNITY_COLLECTIONS_CHECKS
m_Safety = stream.m_Safety;
CollectionHelper.SetStaticSafetyId(ref m_Safety, ref s_staticSafetyId.Data, "Unity.Collections.NativeStream.Writer");
m_Length = int.MaxValue;
m_MinIndex = int.MinValue; <----------------
m_MaxIndex = int.MinValue; <-------------------
#endif
#if ENABLE_UNITY_COLLECTIONS_CHECKS || UNITY_DOTS_DEBUG
m_PassByRefCheck = null;
#endif
}`

#

If I must append to the stream everything I'm generating on IJobEntity, how to do this parallel otherwise? Should I create as many buffers as... what?

#

And I'm using ECS 1.2