Solved

CRCs - Calculating them quickly for a File

Posted on 1997-06-20
4
365 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
  • 2
4 Comments
 
LVL 3

Expert Comment

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now