private void SaveData(MemoryContract contract)
		{
			int offset = MemoryContractOffset;

			Write(ref offset, contract.Variables.Count);
			foreach (var variable in contract.Variables)
			{
				Write(ref offset, variable.Key);
				Write(ref offset, variable.Value.Count);
				foreach (var variableContract in variable.Value)
				{
					Write(ref offset, variableContract.InstaceId);
					Write(ref offset, variableContract.Value);
				}
			}

			Write(ref offset, contract.VariableOperations.Count);
			foreach (var varOperation in contract.VariableOperations)
			{
				Write(ref offset, varOperation.Key);
				Write(ref offset, (int)varOperation.Value);
			}

			if (offset > MemoryMappedFileSize)
			{
				throw new InternalBufferOverflowException();
			}

			OnDataChanged();
		}
		private MemoryContract LoadData()
		{
			int offset = MemoryContractOffset;
			var contract = new MemoryContract();

			int variablesCount = ReadInt32(ref offset);
			for (int i = 0; i < variablesCount; i++)
			{
				var list = new List<VariableConract>();
				contract.Variables[ReadString(ref offset)] = list;

				int variableContractsCount = ReadInt32(ref offset);
				for (int j = 0; j < variableContractsCount; j++)
				{
					list.Add(new VariableConract
						{
							InstaceId = ReadInt32(ref offset),
							Value = ReadDouble(ref offset)
						});
				}
			}

			int variableOperationsCount = ReadInt32(ref offset);
			for (int i = 0; i < variableOperationsCount; i++)
			{
				contract.VariableOperations[ReadString(ref offset)] = (VariableOperations) ReadInt32(ref offset);
			}

			return contract;
		}
		private int GetLastTickOfSlowestInstance(MemoryContract contract)
		{
			if (_instancesCount == 0) return 0;
			int result = int.MaxValue;
			for (int i = 0; i < _instancesCount; ++i)
			{
				if (GetInstanceStatus(i) == InstanceStatus.Deinitialized) continue;
				int tick = GetInstanceTime(i);
				result = Math.Min(result, tick);
			}
			return result;
		}
        private void SaveData(MemoryContract contract)
        {
            int offset = MemoryContractOffset;

            Write(ref offset, contract.Variables.Count);
            foreach (var variable in contract.Variables)
            {
                Write(ref offset, variable.Key);
                Write(ref offset, variable.Value.Count);
                foreach (var variableContract in variable.Value)
                {
                    Write(ref offset, variableContract.InstaceId);
                    Write(ref offset, variableContract.Value);
                }
            }

            Write(ref offset, contract.VariableOperations.Count);
            foreach (var varOperation in contract.VariableOperations)
            {
                Write(ref offset, varOperation.Key);
                Write(ref offset, (int)varOperation.Value);
            }

            if (offset > MemoryMappedFileSize)
            {
                throw new InternalBufferOverflowException();
            }

            OnDataChanged();
        }
        private MemoryContract LoadData()
        {
            int offset = MemoryContractOffset;
            var contract = new MemoryContract();

            int variablesCount = ReadInt32(ref offset);
            for (int i = 0; i < variablesCount; i++)
            {
                var list = new List<VariableConract>();
                contract.Variables[ReadString(ref offset)] = list;

                int variableContractsCount = ReadInt32(ref offset);
                for (int j = 0; j < variableContractsCount; j++)
                {
                    list.Add(new VariableConract
                        {
                            InstaceId = ReadInt32(ref offset),
                            Value = ReadDouble(ref offset)
                        });
                }
            }

            int variableOperationsCount = ReadInt32(ref offset);
            for (int i = 0; i < variableOperationsCount; i++)
            {
                contract.VariableOperations[ReadString(ref offset)] = (VariableOperations) ReadInt32(ref offset);
            }

            return contract;
        }
 private int GetLastTickOfSlowestInstance(MemoryContract contract)
 {
     if (_instancesCount == 0) return 0;
     int result = int.MaxValue;
     for (int i = 0; i < _instancesCount; ++i)
     {
         if (GetInstanceStatus(i) == InstanceStatus.Deinitialized) continue;
         int tick = GetInstanceTime(i);
         result = Math.Min(result, tick);
     }
     return result;
 }