internal override void InternalDeserialize(NetIncomingMessage lidgrenMsg) { base.InternalDeserialize(lidgrenMsg); NumBytes = lidgrenMsg.ReadInt32(); if (Data.Length < NumBytes) { Data = new byte[NumBytes]; } lidgrenMsg.ReadBytes(Data, 0, NumBytes); CachedQlz.Decompress(ref Data, out NumBytes); }
public void Deserialize(NetIncomingMessage lidgrenMsg) { Module = lidgrenMsg.ReadString(); NumBytes = lidgrenMsg.ReadInt32(); if (Data.Length < NumBytes) { Data = new byte[NumBytes]; } lidgrenMsg.ReadBytes(Data, 0, NumBytes); CachedQlz.Decompress(ref Data, out NumBytes); }
public void Deserialize(NetIncomingMessage lidgrenMsg) { ContractGuid = GuidUtil.Deserialize(lidgrenMsg); NumBytes = lidgrenMsg.ReadInt32(); if (Data.Length < NumBytes) { Data = new byte[NumBytes]; } lidgrenMsg.ReadBytes(Data, 0, NumBytes); CachedQlz.Decompress(ref Data, out NumBytes); }
public static void ThreadSafeDecompress(object lockObj, ref byte[] data, int length, out int numBytes) { lock (lockObj) { if (CachedQlz.IsCompressed(data, length)) { CachedQlz.Decompress(ref data, out numBytes); } else { numBytes = length; } } }
public void DecompressThreadSafe() { const int iterations = 1000; var length = 100000; var data = Encoding.ASCII.GetBytes(TestCommon.RandomString(length)); CachedQlz.Compress(ref data, ref length); var task1Ok = true; var task1 = Task.Run(() => { try { for (var i = 0; i < iterations; i++) { var clone = TestCommon.CloneArray(data); CachedQlz.Decompress(ref clone, out _); } } catch (Exception) { task1Ok = false; } }); var task2Ok = true; var task2 = Task.Run(() => { try { for (var i = 0; i < iterations; i++) { var clone = TestCommon.CloneArray(data); CachedQlz.Decompress(ref clone, out _); } } catch (Exception) { task2Ok = false; } }); task1.Wait(); task2.Wait(); Assert.IsTrue(task1Ok); Assert.IsTrue(task2Ok); }
internal override void InternalDeserialize(NetIncomingMessage lidgrenMsg) { base.InternalDeserialize(lidgrenMsg); SubspaceId = lidgrenMsg.ReadInt32(); DominantVesselId = GuidUtil.Deserialize(lidgrenMsg); WeakVesselId = GuidUtil.Deserialize(lidgrenMsg); NumBytes = lidgrenMsg.ReadInt32(); if (FinalVesselData.Length < NumBytes) { FinalVesselData = new byte[NumBytes]; } lidgrenMsg.ReadBytes(FinalVesselData, 0, NumBytes); CachedQlz.Decompress(ref FinalVesselData, out NumBytes); }
public void DecompressDataReuseArrays() { var numBytes = 4500; var text = Encoding.ASCII.GetBytes(TestCommon.RandomString(numBytes)); CachedQlz.Compress(ref text, ref numBytes); CachedQlz.Decompress(ref text, out _); numBytes = 5500; text = Encoding.ASCII.GetBytes(TestCommon.RandomString(numBytes)); CachedQlz.Compress(ref text, ref numBytes); var memBefore = GC.GetTotalMemory(true); CachedQlz.Decompress(ref text, out _); var memAfter = GC.GetTotalMemory(true); Assert.IsTrue(memAfter <= memBefore); }