/// <summary> /// /// </summary> /// <param name="len"></param> public unsafe void ZipCompress(int start, int size) { try { Stopwatch sw = new Stopwatch(); sw.Start(); if (System.IO.Compression.BrotliEncoder.TryCompress(new ReadOnlySpan <byte>((void *)(this.Handles[0] + start), size), new Span <byte>((void *)(mCompressedDataPointer + 8), (int)this.AllocSize - 8), out mCompressedDataSize)) { MemoryHelper.WriteInt32((void *)mCompressedDataPointer, 0, mCompressedDataSize); MemoryHelper.WriteInt32((void *)(mCompressedDataPointer), 4, size); //var vtmp = Marshal.AllocHGlobal(size); //int decodesize = 0; //System.IO.Compression.BrotliDecoder.TryDecompress(new ReadOnlySpan<byte>((void*)(mCompressedDataPointer + 8), (int)mCompressedDataSize), new Span<byte>((void*)vtmp, size), out decodesize); //Marshal.FreeHGlobal(vtmp); sw.Stop(); LoggerService.Service.Info("CompressMemory", this.Name + " ZipCompress 耗时:" + sw.ElapsedMilliseconds + " old size:" + size + " new size:" + mCompressedDataSize); } else { sw.Stop(); LoggerService.Service.Warn("CompressMemory", this.Name + " ZipCompress 耗时:" + sw.ElapsedMilliseconds + " 压缩失败!"); } } catch (Exception ex) { LoggerService.Service.Erro("CompressMemory", ex.Message); } }
public void WriteIntDirect(long offset, int value) { MemoryHelper.WriteInt32((void *)mHandles, offset, value); //IntPtr hd; //long ost; //if (IsCrossDataBuffer(offset, 4)) //{ // WriteBytesDirect(offset, BitConverter.GetBytes(value)); //} //else //{ // hd = RelocationAddress(offset, out ost); // MemoryHelper.WriteInt32((void*)hd, ost, value); //} }
public void Add(int value, DateTime time, byte qulity) { if (mCount >= mLimite) { int newCount = (int)(mCount * 1.2); Resize(newCount); mLimite = newCount; } MemoryHelper.WriteInt32((void *)handle, mPosition, value); mPosition += 4; MemoryHelper.WriteDateTime((void *)handle, mCount * 8 + mTimeAddr, time); // mDataBuffer[mCount + mQulityAddr] = qulity; Marshal.WriteByte(handle + mCount + mQulityAddr, qulity); mCount++; }
public void WriteIntDirect(long offset, int value) { MemoryHelper.WriteInt32((void *)mHandles, offset, value); }
/// <summary> /// /// </summary> /// <param name="offset"></param> /// <param name="value"></param> public virtual void WriteInt(long offset, int value) { MemoryHelper.WriteInt32((void *)mHandles, offset, value); Position = offset + 4; }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="time"></param> /// <param name="qulity"></param> public void Add(object value, DateTime time, byte qulity) { if (mCount >= mLimite) { int newCount = (int)(mCount * 1.2); Resize(newCount); mLimite = newCount; } switch (mDataType) { case 0: Marshal.WriteByte(handle + mPosition, (byte)(((bool)value)?1:0)); mPosition++; break; case 1: Marshal.WriteByte(handle + mPosition, (byte)value); //mDataBuffer[mPosition] = (byte)value; mPosition++; break; case 2: MemoryHelper.WriteShort((void *)handle, mPosition, Convert.ToInt16(value)); mPosition += 2; break; case 3: MemoryHelper.WriteUShort((void *)handle, mPosition, Convert.ToUInt16(value)); mPosition += 2; break; case 4: MemoryHelper.WriteInt32((void *)handle, mPosition, Convert.ToInt32(value)); mPosition += 4; break; case 5: MemoryHelper.WriteUInt32((void *)handle, mPosition, Convert.ToUInt32(value)); mPosition += 4; break; case 6: MemoryHelper.WriteInt64((void *)handle, mPosition, Convert.ToInt64(value)); mPosition += 8; break; case 7: MemoryHelper.WriteUInt64((void *)handle, mPosition, Convert.ToUInt64(value)); mPosition += 8; break; case 8: MemoryHelper.WriteFloat((void *)handle, mPosition, Convert.ToSingle(value)); mPosition += 4; break; case 9: MemoryHelper.WriteDouble((void *)handle, mPosition, Convert.ToDouble(value)); mPosition += 8; break; case 10: try { MemoryHelper.WriteDateTime((void *)handle, mPosition, (DateTime)value); } catch { } mPosition += 8; break; case 11: var sdata = Encoding.Unicode.GetBytes((string)value); MemoryHelper.WriteByte((void *)handle, mPosition, (byte)sdata.Length); mPosition++; Marshal.Copy(sdata, 0, handle + mPosition, sdata.Length); mPosition += sdata.Length; break; case 12: Add((IntPointData)value, time, qulity); return; case 13: Add((UIntPointData)value, time, qulity); return; case 14: Add((IntPoint3Data)value, time, qulity); return; case 15: Add((UIntPoint3Data)value, time, qulity); return; case 16: Add((LongPointData)value, time, qulity); return; case 17: Add((ULongPointData)value, time, qulity); return; case 18: Add((LongPoint3Data)value, time, qulity); return; case 19: Add((ULongPoint3Data)value, time, qulity); return; } MemoryHelper.WriteDateTime((void *)handle, mCount * 8 + mTimeAddr, time); Marshal.WriteByte(handle + mCount + mQulityAddr, (byte)qulity); // mDataBuffer[mCount + mQulityAddr] = qulity; mCount++; }