Results 1 to 2 of 2

Thread: QFile map

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default QFile map

    Now I need to read/write a large file(15G),I want to accelerate the speed of reading /writing file, I find that the map function of QFilecan do it,I try it as follows,but I find that speed is the same as the common read/write file,why?

    Qt Code:
    1. QFile objInputFile("test.sgy");
    2. if (!objInputFile.open(QIODevice::Unbuffered | QIODevice::ReadOnly))
    3. {
    4. return false;
    5. }
    6.  
    7. QFile objOutputFile("out.sgy");
    8. if (!objOutputFile.open(QIODevice::Unbuffered | QIODevice::WriteOnly | QIODevice::Truncate))
    9. {
    10. objInputFile.close();
    11. return false;
    12. }
    13.  
    14. uchar * pData = NULL;
    15. qint64 m_qint64FileOffset = 0;
    16. qint64 m_qint64InputFileSize = objInputFile.size();
    17. qint64 m_unBlockSize=m_qint64InputFileSize;
    18.  
    19. qint64 unTmpBlockSize = m_qint64InputFileSize/10;
    20.  
    21. while(m_qint64FileOffset < m_qint64InputFileSize)
    22. {
    23. if (m_qint64InputFileSize-m_qint64FileOffset <unTmpBlockSize)
    24. unTmpBlockSize=m_qint64InputFileSize-m_qint64FileOffset;
    25. pData = objInputFile.map(m_qint64FileOffset,unTmpBlockSize);
    26.  
    27. if (pData == NULL)
    28. {
    29. objInputFile.close();
    30. objOutputFile.close();
    31. return false;
    32. }
    33. if (objOutputFile.write((char*)pData,unTmpBlockSize) == -1)
    34. {
    35. objInputFile.close();
    36. objOutputFile.close();
    37. return false;
    38. }
    39.  
    40. m_qint64FileOffset += unTmpBlockSize;
    41. if (!objInputFile.unmap(pData))
    42. {
    43. objInputFile.close();
    44. objOutputFile.close();
    45. return false;
    46. }
    47. }
    48.  
    49. objInputFile.unmap(pData);
    50. objInputFile.close();
    51. objOutputFile.close();
    52. return true;
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFile map

    For large files, the speed will be the same regardless of the method you use because the overall performance will be based on the OS/disk controller and disks themselves rather than the overhead of the libraries you are using.

Similar Threads

  1. c structure & Qfile
    By eva2002 in forum Qt Programming
    Replies: 15
    Last Post: 25th January 2010, 08:37
  2. Rewind QFile
    By Tino in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2009, 09:41
  3. How to use the QFile.map
    By xtfllbl in forum Qt Programming
    Replies: 1
    Last Post: 27th September 2009, 08:25
  4. QFile using utf-8
    By Mr.QT in forum Qt Programming
    Replies: 3
    Last Post: 30th April 2009, 12:17
  5. QFile, QTextStream
    By Zergi in forum Newbie
    Replies: 1
    Last Post: 12th January 2008, 19:40

Tags for this Thread

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.