예제 #1
0
            internal JobHandle Schedule(EntityQuery entityQuery, ComponentSystemBase system, JobHandle jobHandle)
            {
                size = entityQuery.CalculateEntityCount();
                if (capacity < size)
                {
                    // Extend capacity if needed
                    capacity = size;

                    values = new float[capacity];

                    buffer.Dispose();
                    buffer = new ComputeBuffer(capacity, sizeof(float));

                    handler.Dispose();
                    handler = GCHandle.Alloc(values, GCHandleType.Pinned);
                }

                return(prevJobHandle = new FillArrayJob
                {
                    sizeOfValue = SizeOfValue,
                    dynamicType = system.GetArchetypeChunkComponentTypeDynamic(ComponentType.ReadOnly <BoneIndexOffset>()),

                    defaultValue = UnsafeUtility.AddressOf(ref defaultValue),
                    dst = (void *)handler.AddrOfPinnedObject(),
                }.Schedule(entityQuery, jobHandle));
            }
예제 #2
0
        public unsafe void ReadBuffer(NativeList <char> result)
        {
            var tmp_buff = new NativeList <Char16>(Allocator.Temp);

            if (_blockPos < _blockNum)
            {
                this.ReadStream();
                fixed(byte *byte_ptr = _byteBuffer)
                {
                    var handle = new GCHandle <Decoder>();

                    handle.Create(_decoder);
                    _worker.DecodeTextIntoBuffer(byte_ptr, _byteLength, handle);
                    handle.Dispose();
                    _worker.GetChars(tmp_buff);
                }
            }

            if (!_worker.IsEmpty)
            {
                _worker.GetInternalBuffer(tmp_buff);
            }
            result.AddRange(tmp_buff.GetUnsafePtr(), tmp_buff.Length);
            tmp_buff.Dispose();
        }
예제 #3
0
        private void InitState(GCHandle <string> pathHandle, bool disposePathHandle, long fileSize, int bufferSize)
        {
            if (fileSize < 0)
            {
                throw new ArgumentOutOfRangeException("file size must be > 0.");
            }

            if (_info.Target->disposePathHandle)
            {
                _path.Dispose();
            }
            _path = pathHandle;
            _info.Target->disposePathHandle = disposePathHandle;
            _info.Target->fileSize          = fileSize;
            ;
            long tgtBufferSize = bufferSize;

            if (tgtBufferSize < Define.MinBufferSize)
            {
                tgtBufferSize = Define.MinBufferSize;
            }
            if (tgtBufferSize > Int32.MaxValue)
            {
                tgtBufferSize = Int32.MaxValue;
            }

            // for debug
            //tgtBufferSize = 64;

            if (bufferSize < 0 || _info.Target->fileSize < tgtBufferSize)
            {
                // buffering entire the file
                _info.Target->blockSize = (int)_info.Target->fileSize;
                _info.Target->blockNum  = 1;
            }
            else
            {
                // buffering as blocking
                _info.Target->blockSize = (int)tgtBufferSize;
                _info.Target->blockNum  = (int)(_info.Target->fileSize / _info.Target->blockSize) + 1;
            }
            _info.Target->blockPos = 0;

            this.Reallocate();
        }
예제 #4
0
            private void DisposeHandle()
            {
                if (_info.Target->disposeHandle)
                {
                    _decoder.Dispose();

                    _data.Dispose();
                    _timer.Dispose();

                    _info.Target->disposeHandle = false;
                }
            }
예제 #5
0
        private unsafe void ReadLinesImpl(IAddResult result, int max_lines)
        {
            int line_count = 0;

            line_count += this.PickLinesImpl(result, max_lines);
            if (line_count == max_lines)
            {
                return;
            }

            _lines.Clear();
            while (line_count < max_lines)
            {
                if (_blockPos < _blockNum && _worker.IsEmpty)
                {
                    this.ReadStream();
                    fixed(byte *byte_ptr = _byteBuffer)
                    {
                        var handle = new GCHandle <Decoder>();

                        handle.Create(_decoder);
                        _worker.DecodeTextIntoBuffer(byte_ptr, _byteLength, handle);
                        handle.Dispose();
                        _worker.GetLines(_lines);
                    }
                }

                line_count += this.PickLinesImpl(result, max_lines - line_count);
                if (line_count == max_lines)
                {
                    return;
                }

                if (_blockPos == _blockNum)
                {
                    // if final part do not have LF.
                    if (!_worker.IsEmpty)
                    {
                        var buff = new NativeList <Char16>(Allocator.Temp);
                        _worker.GetInternalBuffer(buff);
                        result.AddResult((char *)buff.GetUnsafePtr(), buff.Length);
                        buff.Dispose();
                    }

                    // reach EOF
                    break;
                }
            }
        }
예제 #6
0
        public unsafe void ReadLinesFromBuffer(NativeStringList result)
        {
            var ret = new Result_NSL();

            ret.result = result;

            if (_blockPos < _blockNum)
            {
                this.ReadStream();
                fixed(byte *byte_ptr = _byteBuffer)
                {
                    var handle = new GCHandle <Decoder>();

                    handle.Create(_decoder);
                    _worker.DecodeTextIntoBuffer(byte_ptr, _byteLength, handle);
                    handle.Dispose();
                    _worker.GetLines(_lines);
                }
            }

            // read all lines in buffer
            this.PickLinesImpl(ret, int.MaxValue);
            _lines.Clear();

            if (_blockPos == _blockNum)
            {
                // if final part do not have LF.
                if (!_worker.IsEmpty)
                {
                    using (var buff = new NativeList <Char16>(Allocator.Temp))
                    {
                        _worker.GetInternalBuffer(buff);
                        result.Add((char *)buff.GetUnsafePtr(), buff.Length);
                    }
                }
            }
        }
예제 #7
0
 public void Dispose()
 {
     _gchandle.Dispose();
 }