Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Crc32
Message
De
25/08/2011 07:23:56
 
 
À
25/08/2011 05:28:20
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Re: Crc32
Versions des environnements
Environment:
C# 4.0
Divers
Thread ID:
01521077
Message ID:
01521746
Vues:
35
>Boy you've really dived into this one :-} Want to try it when I get the time.
>At first I assumed you had hard-wired the buffer count to your machine specs but I see you're doing it dynamically based on the environment....
>
>



Opening the file with FileStream(), async is worse

using File.OpenRead() is just a bit better - but nothing to write home about

Quick code for async reads
		public Int32 GetCRC(Stream stream)
		{
			UInt32 crcCurrent = CRC32InitValue;

			byte[][] buf = new byte[2][];

			buf[0] = new byte[TotalBufferSize];
			buf[1] = new byte[TotalBufferSize];

			UInt32[] bufferCRC = new UInt32[NumberOfBuffers];

			int count;
			object state = new object();

			int bufCurrent = 0;

			IAsyncResult result = stream.BeginRead(buf[bufCurrent], 0, TotalBufferSize, null, state);
			count = stream.EndRead(result);


			while (count != 0)
			{
				if (count < TotalBufferSize)
				{
					crcCurrent = HashBlock16(crcCurrent, buf[bufCurrent], 0, count);
					break;
				}

				result = stream.BeginRead(buf[(bufCurrent + 1) & 0x1], 0, TotalBufferSize, null, state);
				GetBufferCRC(bufferCRC, buf[bufCurrent]);
				crcCurrent = MergeCRCs(crcCurrent, bufferCRC);

				bufCurrent = (bufCurrent + 1) & 0x1;
				count = stream.EndRead(result);

			}
			return unchecked((Int32)~crcCurrent);
		}
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform