什么将是内存消耗更少的设计?
我知道 ref 关键字通过引用传递参数,并且不会在函数参数中获取新的内存引用。我认为第一个设计将比第二个设计更有效。我对么?
1)。
public void SyncWeighEntityData(string sqlConnectionString, int weighBridgeID, string weibridgeName, int lastSyncedTicetNo, string imagesPath)
{
using (var cn = DBUtils.GetNewOpenConnection(sqlConnectionString))
{
var query = "SELECT * FROM [WeighEntry] WHERE TicketNo > @TicketNo";
var lastTicketNo = cn.Query<int>("SELECT MAX(TicketNo) FROM [WeighEntry]").Single();
var results = cn.Query(query, new { TicketNo = lastSyncedTicetNo }).ToList();
results.ForEach(x => x.WeighBridgeID = weighBridgeID);
cn.Close();
SyncImages(ref results, ref imagesPath, ref weibridgeName);
SyncWeighEntityDataToLocalDB(ref results, ref lastTicketNo, ref weighBridgeID);
}
}
private void SyncImages(ref List<dynamic> WeightEntitiesToSync, ref string imagesPath, ref string weibridgeName)
{
foreach (var item in WeightEntitiesToSync)
{
for (int i = 0; i < 4; i++)
{
SaveTicketImageOnLocalPath(Path.GetFullPath(CommonResources.DecodeFromBase64(imagesPath) + string.Format($"\\{item.TicketNo}_CropedIn.Jpg")), item.WeighBridgeID, weibridgeName, string.Format($"{item.TicketNo}_CropedIn.Jpg"));
}
}
}
private void SyncWeighEntityDataToLocalDB(ref List<dynamic> WeightEntitiesToSync, ref int lastTicketNo, ref int weighBridgeID)
{
// Code to save data
}
或 2)。
public void SyncWeighEntityData(string sqlConnectionString, int weighBridgeID, string weibridgeName, int lastSyncedTicetNo, string imagesPath)
{
using (var cn = DBUtils.GetNewOpenConnection(sqlConnectionString))
{
var query = "SELECT [TicketNo],[VihNo],[Supervisor],[Driver],[Cleaner],[SealNO1],[SealNO2],[SealNO3],[ContainerNo],[ItemDis],[TimeIn],[TimeOut],[Weigh1],[Weigh2],[Remarks1st],[Remarks2ed],[CustName],[DateIn],[DateOut],[GinorGrnNo],[UserName],[AccountBillCount],[StoresBillCount],[CustomerBillCount] FROM [WeighEntry] WHERE TicketNo > @TicketNo";
var lastTicketNo = cn.Query<int>("SELECT MAX(TicketNo) FROM [WeighEntry]").Single();
var results = cn.Query(query, new { TicketNo = lastSyncedTicetNo }).ToList();
results.ForEach(x => x.WeighBridgeID = weighBridgeID);
cn.Close();
SyncImages( results, imagesPath, weibridgeName);
SyncWeighEntityDataToLocalDB( results, lastTicketNo,weighBridgeID);
}
}
private void SyncImages( List<dynamic> WeightEntitiesToSync, string imagesPath, string weibridgeName)
{
foreach (var item in WeightEntitiesToSync)
{
for (int i = 0; i < 4; i++)
{
SaveTicketImageOnLocalPath(Path.GetFullPath(CommonResources.DecodeFromBase64(imagesPath) + string.Format($"\\{item.TicketNo}_CropedIn.Jpg")), item.WeighBridgeID, weibridgeName, string.Format($"{item.TicketNo}_CropedIn.Jpg"));
}
}
}
private void SyncWeighEntityDataToLocalDB( List<dynamic> WeightEntitiesToSync, int lastTicketNo, int weighBridgeID)
{
// Code to save data
}