Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GetSpread<T> : IPluginEvaluate
- {
- #region fields & pins
- [Input("Input")]
- IInStream<IInStream<T>> FInput;
- //[Input("Input Bin Size")]
- //IInStream<int> FInputBinSize;
- [Input("Offset")]
- IInStream<int> FOffset;
- [Input("Count", DefaultValue = 1, MinValue = 0)]
- IInStream<int> FCount;
- [Output("Output")]
- IOutStream<IInStream<T>> FOutput;
- //[Output("Output Bin Size")]
- //IOutStream<int> FOutputBinSize;
- #endregion fields & pins
- //called when data for any output pin is requested
- public void Evaluate(int spreadMax)
- {
- FOutput.Length = StreamUtils.GetMaxLength(FInput, FOffset, FCount);
- var inputBuffer = MemoryPool<IInStream<T>>.GetArray();
- var offsetBuffer = MemoryPool<int>.GetArray();
- var countBuffer = MemoryPool<int>.GetArray();
- try
- {
- using (var inputReader = FInput.GetCyclicReader())
- using (var offsetReader = FOffset.GetCyclicReader())
- using (var countReader = FCount.GetCyclicReader())
- using (var outputWriter = FOutput.GetWriter())
- {
- var numSlicesToWrite = FOutput.Length;
- while (numSlicesToWrite > 0)
- {
- var blockSize = Math.Min(numSlicesToWrite, inputBuffer.Length);
- inputReader.Read(inputBuffer, 0, blockSize);
- offsetReader.Read(offsetBuffer, 0, blockSize);
- countReader.Read(countBuffer, 0, blockSize);
- for (int i = 0; i < blockSize; i++)
- {
- inputBuffer[i] = inputBuffer[i].GetRange(offsetBuffer[i], countBuffer[i]);
- }
- numSlicesToWrite -= outputWriter.Write(inputBuffer, 0, blockSize);
- }
- }
- }
- finally
- {
- MemoryPool<IInStream<T>>.PutArray(inputBuffer);
- MemoryPool<int>.PutArray(offsetBuffer);
- MemoryPool<int>.PutArray(countBuffer);
- }
- }
- }
Add Comment
Please, Sign In to add comment