public void Evaluate(int spreadMax) { if (FStreamIn.SliceCount == 0 || FStreamIn[0] == null || FStreamIn[0].Length == 0) { spreadMax = 0; } else { spreadMax = FStreamIn.SliceCount; } FStreamOut.ResizeAndDispose(spreadMax, () => new MemoryStream()); for (int i = 0; i < spreadMax; i++) { var inputStream = FStreamIn[i]; var outputStream = FStreamOut[i]; inputStream.Position = 0; outputStream.Position = 0; FStreamOut[i].SetLength(0); var length = (int)inputStream.Length; IntPtr contentPtr = Marshal.AllocHGlobal(length); byte[] memory = new byte[length]; inputStream.Read(memory, 0, length); Marshal.Copy(memory, 0, contentPtr, length); int maxCompressedLength = SnappyCodec.GetMaximumCompressedLength(length); this.compressedFrameData = new byte[maxCompressedLength]; fixed(byte *bptr = &this.compressedFrameData[0]) { this.compressedSize = maxCompressedLength; SnappyCodec.Compress((byte *)contentPtr, length, bptr, ref this.compressedSize); byte[] output = new byte[this.compressedSize]; Marshal.Copy((IntPtr)bptr, output, 0, this.compressedSize); outputStream.Write(this.compressedFrameData, 0, this.compressedSize); } Marshal.FreeHGlobal(contentPtr); } FStreamOut.Flush(true); }