public void Insert(T Row) { long position = CurrentTablePosition; byte[] PositionByte = BitConverter.GetBytes(CurrentTablePosition); foreach (PropertyInfo property in Properties) { object propertyValue = property.GetValue(Row); if (propertyValue != null) { int column = ColumnPosition[property.Name]; Columns[column].Insert(propertyValue, CurrentTablePosition, PositionByte); } } long size = position + TableRowSize; CheckTableSize(size); using (var accessor = MemoryMappedTableFile.CreateViewAccessor(position, TableRowSize, MemoryMappedFileAccess.Write)) { byte[] Buffer = ION.SerializeObject(Row, PadRight: true, PadAmount: TableRowSize); accessor.WriteArray(0, Buffer, 0, Buffer.Length); } CurrentTablePosition += TableRowSize; }
public void Insert(object Value, long CurrentTablePosition, byte[] PositionByte) { T ValueConvert = (T)Value; ColumnMapper.Add(ValueConvert, new MapperFilePostion(CurrentTablePosition, MemoryMappedColumnMapStream.Position)); CheckTableMapSize(MemoryMappedColumnMapStream.Position + MapRowSize); byte[] ValueByte = ION.SerializeObject(ValueConvert, PadRight: true, PadAmount: MapRowSizeNoPosition); MemoryMappedColumnMapStream.Write(ValueByte, 0, ValueByte.Length); MemoryMappedColumnMapStream.Write(PositionByte, 0, PositionByte.Length); MemoryMappedColumnMapCountAccessor.Write(0, ColumnMapper.Count); }
public void Update(object OldValue, object NewValue) { T OldValueConvert = (T)OldValue; T NewValueConvert = (T)NewValue; MapperFilePostion mapperFilePostion = ColumnMapper[OldValueConvert]; ColumnMapper.Remove(OldValueConvert); ColumnMapper.Add(NewValueConvert, mapperFilePostion); byte[] ValueByte = ION.SerializeObject(NewValueConvert, PadRight: true, PadAmount: MapRowSize); using (var accessor = MemoryMappedColumnMapFile.CreateViewAccessor(mapperFilePostion.MapPosition, MapRowSize, MemoryMappedFileAccess.Write)) { accessor.WriteArray(0, ValueByte, 0, ValueByte.Length); } MemoryMappedColumnMapCountAccessor.Write(0, ColumnMapper.Count); }
public void Update(T Row) { DateTime start = DateTime.Now; object propertyValue = KeyColumn.GetValue(Row); long Position = Columns[KeyColumnIndex].Equal(propertyValue).TablePosition; T Original = Get(Position); foreach (PropertyInfo property in Properties) { object newValue = property.GetValue(Row); object oldValue = property.GetValue(Original); if (newValue != null && !newValue.Equals(oldValue)) { int column = ColumnPosition[property.Name]; Columns[column].Update(oldValue, newValue); } } using (var accessor = MemoryMappedTableFile.CreateViewAccessor(Position, TableRowSize, MemoryMappedFileAccess.Write)) { byte[] Buffer = ION.SerializeObject(Row, PadRight: true, PadAmount: TableRowSize); accessor.WriteArray(0, Buffer, 0, Buffer.Length); } }
static void Main(string[] args) { //PREP Model m = new Model(); PopulateTestModel(ref m); //ION - SERIALIZE Stopwatch sw = Stopwatch.StartNew(); byte[] ion = ION.SerializeObject(m); sw.Stop(); long ionSerializeTime = sw.ElapsedTicks; //JSON - SERIALIZE sw = Stopwatch.StartNew(); string jsonStr = JsonConvert.SerializeObject(m); sw.Stop(); long jsonSerializeTime = sw.ElapsedTicks; //ION - DESERIALIZE sw = Stopwatch.StartNew(); Model ionDeserialized = ION.DeserializeObject <Model>(ion); sw.Stop(); long ionDeserializeTime = sw.ElapsedTicks; string parity1 = ION.Parity(m); string parity2 = ION.Parity(ionDeserialized); if (parity1 != parity2) { throw new Exception(":-("); } //JSON - DESERIALIZE sw = Stopwatch.StartNew(); Model jsonDeserialized = JsonConvert.DeserializeObject <Model>(jsonStr); sw.Stop(); long jsonDeserializeTime = sw.ElapsedTicks; //SIZE Console.WriteLine("--SIZE--"); Console.WriteLine("ION: " + ion.Length); Console.WriteLine("JSON: " + jsonStr.Length); long max = Math.Max(ion.Length, jsonStr.Length); long min = Math.Min(ion.Length, jsonStr.Length); float perc = ((float)max / (float)min); Console.WriteLine("DIFF: " + (ion.Length < jsonStr.Length ? "-" : "+") + (perc * 100f).ToString() + "% (" + perc.ToString() + "x)"); //SPEED - SERIALIZE Console.WriteLine(Environment.NewLine + "--SERIALIZE SPEED--"); Console.WriteLine("ION: " + ionSerializeTime); Console.WriteLine("JSON: " + jsonSerializeTime); max = Math.Max(ionSerializeTime, jsonSerializeTime); min = Math.Min(ionSerializeTime, jsonSerializeTime); perc = ((float)max / (float)min); Console.WriteLine("DIFF: " + (ionSerializeTime < jsonSerializeTime ? "-" : "+") + (perc * 100f).ToString() + "% (" + perc.ToString() + "x)"); //SPEED - DESERIALIZE Console.WriteLine(Environment.NewLine + "--DESERIALIZE SPEED--"); Console.WriteLine("ION: " + ionDeserializeTime); Console.WriteLine("JSON: " + jsonDeserializeTime); max = Math.Max(ionDeserializeTime, jsonDeserializeTime); min = Math.Min(ionDeserializeTime, jsonDeserializeTime); perc = ((float)max / (float)min); Console.WriteLine("DIFF: " + (ionDeserializeTime < jsonDeserializeTime ? "-" : "+") + (perc * 100f).ToString() + "% (" + perc.ToString() + "x)"); Console.Read(); }