Solved

# CRCs - Calculating them quickly for a File

Posted on 1997-06-20
375 Views

I have written some code to Calculate the CRCs of a bunch of files.

The trouble is that I have done all the CRC calculations using binary digits held in strings so it is VERY S.L.O.W. !!

I did it this way, because it makes the code so easy to understand - but the draw back is that it is slow !

I kind of started to convert my code over to using Integers and doing everything using Bitwise operators (SHL, XOR, etc) but (after my very early benchmarks) I didn't get the speed improvement I was desperate for.

The trouble is that my CRC code needs to be finished very quickly, so I have sort of run out of time.

I need some very fast code to calculate and return the CRC for a file, which I can then call for all files in my list.

I am not too fusy about whether 16 or 32 bit CRCs are calculated, as long as the code works under 16 and 32 bit Delphi and is fast.

Can anybody help ?

I have assigned a lot of points to this question to try and get some good quick help on this.

TIA
Moose
0
Question by:moose032797
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 3

Expert Comment

ID: 1337332
It might be slow because you are reading from the disk file
often...

Try reading the entire file into an array of bytes...you can
do all this with two commands...a GetMem and then a read...
can't rmember what the read command is...I do remember seeing
it help...perhaps a stream??

Anyhow, if you do all your calculations in memory, then it
should be dramatically faster...
0

Author Comment

ID: 1337333
No, I am reading 4 KB buffer at once, so it is definetely how I have done the calculations.

I have now converted my STRING based calculations to Long Integers - the problem now is + / - flipping of numbers.
For me, a 1 in the leftmost bit does not indicate a negative number - unfortunately, I don't know how to get around this under Delphi - as there are no positive only numbers.
So, the CRC results are wrong.

Any ideas anyone ?

Anybody have a good fast algorithm for CRCs ?

Hope somebody can help.

Moose
0

LVL 3

Accepted Solution

sperling earned 100 total points
ID: 1337334
Hope you'll accept this URL as an answer. Got quite a few CRC units.

http://www.pcorner.com/tpc/old/35-101.html

Regards,

Erik.
0

Author Comment

ID: 1337335
Thanks Eric - the link you provided was great.

It took no time at all to take one of these Turbo pascal programs and get it working under Delphi - also improved it as well.

Code works great and is fast !!

Thanks for your help - again !!

Moose
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question