Results 1 to 6 of 6

Thread: The best way to read big file ??

  1. #1
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default The best way to read big file ??

    Hello ,
    Im trying to read a big file, but i want to find what is the best way to do so.
    I ma not worry about the memory as it will be used on machines that have big memory enough to read the whole file at once.

    right now im using textStream to read all in one time, but it still not fast and take time to do so, is there a way to read the file in parallel into QStringList and still keep the order of the lines ??

    some are saying I can not get speed up as I am limited with the disk header to read, and having multiple threads reading from different location in the file will not benefit my performance much.

    Please if anyone have an idea of what is the best way to read the file in memory in parallel or faster way help me.

    Thank you.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The best way to read big file ??

    there's a good answer on stack overflow
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: The best way to read big file ??

    All depends on details.
    If it is some kind of dictionary then and you are reading a text file, then conversion from file specific encoding to unicode may create overhead.
    To reduce that you can disable detection of encoding. Allocation of large number of QStrings is also qute costly.

    If yuo use this data in some kind of data model, then you could load file literally and do conversion to QString every time you are requesting some value (loading vary fast but access to data a bit slower).
    There are lots of other tricks to tweak such things, but this depends on specific application.

  4. #4
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The best way to read big file ??

    Have you considered reading the file in a separate thread and going ahead with whatever processing you plan to do before the entire file has been read?

  5. #5
    Join Date
    Oct 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The best way to read big file ??

    Hi,

    I read such files binary by using standard C++ streams. In order to improve speed i use my own stream buffer and reading in chunks (with buffer size). The interpretation of line ends can be done later directly on the buffer.
    Up to now i don't use multithreading. It makes only sense for me if you need some further interpretation (parsing) of the data.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: The best way to read big file ??

    You could experiement with QFile::map() to slide a window over the file, i.e. map a section of the file into memory, take whatever data you need, map the next section.

    Mapping a file or parts of a file into memory allows the operating system to coordinate file system buffers, optimize read/writes, avoid copying (from FS buffer to application memory), etc.

    Cheers,
    _

Similar Threads

  1. Read contents from the file using QHTTP Read()?
    By Gokulnathvc in forum Newbie
    Replies: 2
    Last Post: 21st June 2011, 08:03
  2. Read from a zip file
    By rajji_saini in forum Qt Programming
    Replies: 2
    Last Post: 21st June 2011, 00:28
  3. How to read a XML file that uses UTF-8?
    By PaladinKnight in forum Newbie
    Replies: 2
    Last Post: 10th April 2010, 13:52
  4. is qt phonon can read realmedia file and divx file
    By fayssalqt in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2009, 15:42
  5. Replies: 1
    Last Post: 20th June 2008, 18:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.