Results 1 to 3 of 3

Thread: More appropriate, section or split?

  1. #1
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Question More appropriate, section or split?

    I am needing to work with some rather large tab separated files (up to 2GB or more). I can read each line in and then split it or use QString::section. But which would be more performant? Given the differences in usage for the two is not a drop in replacement, I'd like to get some idea of which would be better for million+ line counts and the docs are silent on it.

    So, has anyone some experiences between the two for comparison? I'll likely be needing to put the data into a model for display, searching, and sorting, etc. later on. I know I won' tbe needing all of the fields (19).
    --
    The Real Bill

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: More appropriate, section or split?

    If you're really concerned about performance you could use QString::indexOf() and the lightweight wrapper QStringRef.

    QStringRef avoids the memory allocation and reference counting overhead of a standard QString by simply referencing a part of the original string. This can prove to be advantageous in low level code, such as that used in a parser, at the expense of potentially more complex code.
    The code would look something like this:
    Qt Code:
    1. QVector<QStringRef> fields(MAX_FIELDS);
    2. foreach(QString line, ...)
    3. {
    4. int start=0, end=0, validFields=0;
    5. while(validFields < MAX_FIELDS && (end=line.indexOf(',', start)) != -1)
    6. {
    7. fields[validFields++] = QStringRef(&line, start, end-start);
    8. start=end+1;
    9. }
    10. if(validFields < MAX_FIELDS && start<=line.size())
    11. fields[validFields++] = QStringRef(&line, start, line.size()-start);
    12.  
    13. // fields now contain 'validFields' valid entries(some of which might be empty)
    14. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to spud for this useful post:

    ucntcme (12th October 2007)

  4. #3
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: More appropriate, section or split?

    Thanks, that did make it significantly faster, a drop of approximately 33%.
    --
    The Real Bill

Similar Threads

  1. Highlighting selected section on QDateTimeEdit
    By Yorma in forum Qt Programming
    Replies: 4
    Last Post: 3rd May 2013, 12:03
  2. QString split()
    By ShaChris23 in forum Newbie
    Replies: 4
    Last Post: 3rd May 2007, 04:10
  3. Algorithms problem of brackets including.
    By luffy27 in forum General Programming
    Replies: 2
    Last Post: 12th April 2007, 01:10
  4. QGLWidget with multiple monitors
    By Rayven in forum Qt Programming
    Replies: 3
    Last Post: 4th August 2006, 10:28
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.