예제 #1
0
        public uint FastStreamManual(int blockLength, int sourceLength)
        {
            sourceLength = LZ4MemoryHelper.RoundUp(sourceLength, blockLength);
            var targetLength = 2 * sourceLength;

            var context = (LZ4Engine.StreamT *)LZ4MemoryHelper.AllocZero(sizeof(LZ4Engine.StreamT));
            var source  = (byte *)LZ4MemoryHelper.Alloc(sourceLength);
            var target  = (byte *)LZ4MemoryHelper.Alloc(targetLength);

            try
            {
                Lorem.Fill(source, sourceLength);

                var sourceP = 0;
                var targetP = 0;

                while (sourceP < sourceLength && targetP < targetLength)
                {
                    targetP += LZ4Engine64.CompressFastContinue(
                        context,
                        source + sourceP,
                        target + targetP,
                        Math.Min(blockLength, sourceLength - sourceP),
                        targetLength - targetP,
                        1);
                    sourceP += blockLength;
                }

                return(Tools.Adler32(target, targetP));
            }
            finally
            {
                LZ4MemoryHelper.Free(context);
                LZ4MemoryHelper.Free(source);
                LZ4MemoryHelper.Free(target);
            }
        }
예제 #2
0
 /// <see cref="UnmanagedEncodingResource.ReleaseUnmanaged()"/>
 protected override void ReleaseUnmanaged()
 {
     base.ReleaseUnmanaged();
     LZ4MemoryHelper.Free(_context);
 }
예제 #3
0
 /// <see cref="UnmanagedEncodingResource.ReleaseUnmanaged()"/>
 protected override void ReleaseUnmanaged()
 {
     base.ReleaseUnmanaged();
     LZ4MemoryHelper.Free(_inputBuffer);
 }