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. Searching/replacing text in large text files

Searching/replacing text in large text files

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmsquestion
2 Posts 2 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.
  • S Offline
    S Offline
    Stanik
    wrote on last edited by
    #1

    Part of my project is to search/replace or add text in large text files (over 4MB). The sequential approach seems to be very time consuming, therefore I started to think about other methods/procedures. Do you have/know any suggestions, www links, code snippets where I could start from? Thanks in advance, Stan

    D 1 Reply Last reply
    0
    • S Stanik

      Part of my project is to search/replace or add text in large text files (over 4MB). The sequential approach seems to be very time consuming, therefore I started to think about other methods/procedures. Do you have/know any suggestions, www links, code snippets where I could start from? Thanks in advance, Stan

      D Offline
      D Offline
      Dmitriy
      wrote on last edited by
      #2

      Look. I've worked with large files - it was 0.5 GB - 1.5 GB. It was realy large and search and replace took hours with DOS-made program. To impove it I compiled another program. One of the ideas was - first allocate enough memory. You probably can allocate all 4 MB in memory. Second, the program will work much faster if it will work not with bytes, but with DWORD. So, I packed chars in DWORDs by 4 where it was possible. Third, check only first DWORD, if it is equal, compare all. Make a loop with offset by DWORD. After you passed all file, increment it, and so three times to make full search. This algorithm a litle bit more complicated, but I've got speed of like it was just read and write - something like 10-15 minutes. Hope this will help.

      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