Пример #1
0
        static void AllocateBlock(out BlockStream stream, uint uniqueBlockStreamId, Allocator allocator)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (allocator <= Allocator.None)
            {
                throw new ArgumentException("Allocator must be Temp, TempJob or Persistent", "allocator");
            }
#endif

            int blockCount = JobsUtility.MaxJobThreadCount;

            int   allocationSize = sizeof(BlockStreamData) + sizeof(Block *) * blockCount;
            byte *buffer         = (byte *)UnsafeUtility.Malloc(allocationSize, 16, allocator);
            UnsafeUtility.MemClear(buffer, allocationSize);

            var block = (BlockStreamData *)buffer;

            stream.m_Block               = block;
            stream.m_AllocatorLabel      = allocator;
            stream.m_UniqueBlockStreamId = uniqueBlockStreamId;

            block->Allocator  = allocator;
            block->BlockCount = blockCount;
            block->Blocks     = (Block **)(buffer + sizeof(BlockStreamData));

            block->Ranges     = null;
            block->RangeCount = 0;

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Create(out stream.m_Safety, out stream.m_DisposeSentinel, 0, allocator);
#endif
        }
Пример #2
0
        public static JobHandle ScheduleConstruct(out BlockStream blockStream, NativeArray <int> lengthFromIndex0, uint uniqueBlockStreamId, JobHandle dependency, Allocator allocator = Allocator.TempJob)
        {
            AllocateBlock(out blockStream, uniqueBlockStreamId, allocator);
            var jobData = new ConstructJob {
                Length = lengthFromIndex0, BlockStream = blockStream
            };

            return(jobData.Schedule(dependency));
        }
Пример #3
0
        public static JobHandle ScheduleConstruct <T>(out BlockStream blockStream, NativeList <T> forEachCountFromList, uint uniqueBlockStreamId, JobHandle dependency, Allocator allocator = Allocator.TempJob)
            where T : struct
        {
            AllocateBlock(out blockStream, uniqueBlockStreamId, allocator);
            var jobData = new ConstructJobList <T> {
                List = forEachCountFromList, BlockStream = blockStream
            };

            return(jobData.Schedule(dependency));
        }
Пример #4
0
 public Writer(BlockStream stream)
 {
     this = stream;
 }