Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to compare two files quickly?

How to compare two files quickly?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jelfy
    wrote on last edited by
    #1

    I just want to know if the two binary files is same. if i compare them byte by byte , it'll cost a lot of time. is there some good method?

    U H A 3 Replies Last reply
    0
    • J Jelfy

      I just want to know if the two binary files is same. if i compare them byte by byte , it'll cost a lot of time. is there some good method?

      U Offline
      U Offline
      User 307386
      wrote on last edited by
      #2

      No, this is the fastest way. The speed will depend on realization. while (*p1++==*p2++); will be slower than memcmp, fully loaded files are a bit faster then mapped files, etc. The only alternative is some crc generation, but it will be faster only when comparing one file to many. Igor Green http://www.grigsoft.com Compare It! + Synchronize It! : Files and folders comparison never was easier!

      1 Reply Last reply
      0
      • J Jelfy

        I just want to know if the two binary files is same. if i compare them byte by byte , it'll cost a lot of time. is there some good method?

        H Offline
        H Offline
        Henry miller
        wrote on last edited by
        #3

        BAsicly yes. If you want some example source code, search for "diff", which is a unix utility that does what you want. (and many other things)

        H 1 Reply Last reply
        0
        • J Jelfy

          I just want to know if the two binary files is same. if i compare them byte by byte , it'll cost a lot of time. is there some good method?

          A Offline
          A Offline
          Antony M Kancidrowski
          wrote on last edited by
          #4

          A simple check on length would be a quick way to say they are different. Ant. I'm hard, yet soft.
          I'm coloured, yet clear.
          I'm fruity and sweet.
          I'm jelly, what am I? Muse on it further, I shall return!
          - David Walliams (Little Britain)

          1 Reply Last reply
          0
          • H Henry miller

            BAsicly yes. If you want some example source code, search for "diff", which is a unix utility that does what you want. (and many other things)

            H Offline
            H Offline
            Harold Bamford
            wrote on last edited by
            #5

            Henry miller wrote: If you want some example source code, search for "diff", which is a unix utility that does what you want. (and many other things) Good idea. However, "diff" is for text files. If you want to compare binary files, try the unix utility "cmp" If you don't have the source to the unix utilities, try looking at cygwin, a Unix-on-DOS implementation: http://www.cygwin.com[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups