Solved

CRCs - Calculating them quickly for a File

Posted on 1997-06-20
4
375 Views
Last Modified: 2010-04-04

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
Comment
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
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:mheacock
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

by:moose032797
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

by:
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

by:moose032797
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month6 days, 23 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question