Compare the functions of the two files

Source: Internet
Author: User
Function compfile (const F1, F2: string): Boolean; var ms1, MS2: tmemorystream; I, P: integer; B1, B2: byte; begin result: = false; if not (fileexists (F1) and fileexists (F2) Then exit; ms1: = tmemorystream. create; MS2: = tmemorystream. create; ms1.loadfromfile (F1); ms2.loadfromfile (F2); If ms1.size ms2.size then begin ms1.free; ms2.free; exit; end; Result: = true; randomize; for I: = 0 to 9 do begin P: = random (ms1.size); ms1.position: = P; ms2.position: = P; ms1.readbuffer (B1, 1); ms2.readbuffer (B2, 1 ); if B1 B2 then begin result: = false; break; end; ms1.free; ms2.free; end;

  

According to the guidance of "", make a slight modification. However, comparemem is not used to compare all the memory, and 10 samples may be faster.

 function compfile (const F1, F2: string): Boolean; var fs1, fs2: tfilestream; Ms: tmemorystream; I, P: integer; B1, b2: byte; begin result: = false; if not (fileexists (F1) and fileexists (F2) Then exit; fs1: = tfilestream. create (F1, fmopenread); fs2: = tfilestream. create (F2, fmopenread); If fs1.size fs2.size then begin fs1.free; fs2.free; exit; end; Result: = true; randomize; for I: = 0 to 9 do begin P: = random (fs1.size); fs1.position: = P; fs2.position: = P; fs1.readbuffer (B1, 1); fs2.readbuffer (B2, 1); if b1 B2 then begin result: = false; break; end; fs1.free; fs2.free; end;

   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.