我现在是一个初学者,学习几天套接字
private void SendFile(Socket client, string user, string folder1, string folder2, string zipFile)
{
byte[] zipBytes = File.ReadAllBytes(zipFile); //file
string fileInfoStr = user + ","
+ folder1 + ","
+ folder2 + ","
+ Path.GetFileName(zipFile) + ","
+ zipBytes.Length;
byte[] fileInfo = Encoding.UTF8.GetBytes(fileInfoStr);
byte[] fileInfoLen = BitConverter.GetBytes(fileInfo.Length);
var clientData = new byte[4 + fileInfo.Length + zipBytes.Length];
fileInfoLen.CopyTo(clientData, 0);
fileInfo.CopyTo(clientData, 4);
zipBytes.CopyTo(clientData, 4 + fileInfo.Length);
// Begin sending the data to the remote device.
client.BeginSend(clientData, 0, clientData.Length, 0,
new AsyncCallback(SendCallback), client);
Receive(client);
}
例如,问题是我尝试发送一个大的zip文件(300mb),内存使用率高达600mb +。我被困在如何减少内存使用上。谢谢。
您通过不使用内存来减少内存使用量。就像不使用这样的语句: