Results 1 to 8 of 8

Thread: Convert QLinkedList to QList

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    70
    Thanks
    43
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Convert QLinkedList to QList

    I have a dataset with literally millions of entries (often 1 million to 1 billion, depending... it's LIDAR point data, if you care). Currently, my container is a QList of pointers because I need the best performance I can possibly achieve and I like being able to sort it conveniently using multiple parameters (using qStableSort), but insertion and deletion with array-based lists that large is incredibly slow.

    Therefore, I am considering QLinkedList as an alternative for faster insertions/deletions, but the transition means redoing a significant amount of code since it's not indexed. I'm comfortable with using QMap and QHash, but I'm unfamiliar with QLinkedList and would like some feedback from you before I take the dive. This article (http://doc.qt.nokia.com/qq/qq19-containers.html) has been very helpful as I learn the nuances of Qt containers.

    I do not need easy random access at this time, but I do need the ability to sort my data using multiple user-specified parameters—for example, sorting my point data by X, Y, then Z or by Day, Hour, then Second. As far as I can tell, the only way to accomplish this would be to generate sorted QLists (or QMaps?) on-demand, but I cannot determine a simple way to generate a QList from a QLinkedList other than manually iterating through the LinkedList and generating the QList one item at a time. Is there a more efficient way to accomplish this?

    The sorting method can change during runtime. Thanks!

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

    Default Re: Convert QLinkedList to QList

    are you sure this is worth it? Have you checked the difference in performance in release mode? You might be surprised. I will try to find a vid that shows why.

    http://channel9.msdn.com/Events/Goin...up-Cpp11-Style 44:44
    Also you may like to investigate this: http://www.codeproject.com/Articles/...r-ever-EVER-us


    imo, you should not be using linked list.
    Last edited by amleto; 4th June 2012 at 23:28.
    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. The following user says thank you to amleto for this useful post:

    Phlucious (5th June 2012)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Convert QLinkedList to QList

    You have a billion pointers to entries in a QList: that's 8GB just for the pointers (because it will have to be a 64-bit environment at 8 bytes per pointer) before you even have the data they actually point at. If you switch to a QLinkedList you'll instantly double or triple that: forward and backward pointers plus the pointer to the data.

    Do you really need to keep all this data in memory? Have you considered using a relational database with well chosen indexes purely for its sorting and grouping ability? If you use Sqlite you can even keep the database in memory (if you have enough) and still have the speed advantage.

  5. The following user says thank you to ChrisW67 for this useful post:

    Phlucious (5th June 2012)

  6. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Convert QLinkedList to QList

    Just my five cents...

    There are data structures which make it possible to make data representation much more compact than with regular lists. Furthermore some data structures will allow to dump rarely used data to storage and resurect it back to memory if needed. Consider using tree-based structures, they can be much much more efficient than listsand their hierarchical nature will allow to limit memory usage.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    Phlucious (5th June 2012)

  8. #5
    Join Date
    Jan 2011
    Posts
    70
    Thanks
    43
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Convert QLinkedList to QList

    Quote Originally Posted by amleto View Post
    are you sure this is worth it? Have you checked the difference in performance in release mode? You might be surprised. I will try to find a vid that shows why.
    http://channel9.msdn.com/Events/Goin...up-Cpp11-Style 44:44
    Fascinating video! I'm going to have to watch the whole thing sometime soon. Thanks for that link. I wan't convinced that a QLinkedList is a good idea (which is why I posted here before overhauling everything!) and upon viewing those links I'm led to believe that the cost of overhauling my code exceeds any benefit it might provide.

    Quote Originally Posted by ChrisW67 View Post
    Do you really need to keep all this data in memory? Have you considered using a relational database with well chosen indexes purely for its sorting and grouping ability? If you use Sqlite you can even keep the database in memory (if you have enough) and still have the speed advantage.
    Memory can be a concern, which is why I compiled a 64bit version of Qt for use with MSVC2010. I'm interested in learning more about cached processing, but I'm not sure it works in this application—the workflow for my application basically follows this workflow:
    1. Open a LAS file.
    2. Do some stuff with ALL of the points.
    3. Save a new LAS file.
    4. Repeat 1-3 through a directory.

    I haven't considered SQL an option yet since I'm unfamiliar with SQL. I'll consider looking into it.

    Quote Originally Posted by wysota View Post
    There are data structures which make it possible to make data representation much more compact than with regular lists. Furthermore some data structures will allow to dump rarely used data to storage and resurect it back to memory if needed. Consider using tree-based structures, they can be much much more efficient than listsand their hierarchical nature will allow to limit memory usage.
    Frankly, I don't even know where to begin when it comes to designing a tree-based structure for this dataset. I'm interested in learning more.



    Based on everyone's posts, I've accepted the fact that a QLinkedList probably isn't the solution I'm looking for. Since deletions and insertions occur in within a single function, it made sense to me to instead regenerate the QList after marking points for deletion/insertion.

  9. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Convert QLinkedList to QList

    The "best" solution could very much depend on exactly what stuff you are doing to all the points in the LAS file. Your options might also be different if the LAS file has fixed record sizes. For example, there are methods for sorting huge files without loading the entire file into memory. See http://en.wikipedia.org/wiki/External_sorting

  10. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Convert QLinkedList to QList

    Quote Originally Posted by Phlucious View Post
    Memory can be a concern, which is why I compiled a 64bit version of Qt for use with MSVC2010. I'm interested in learning more about cached processing, but I'm not sure it works in this application—the workflow for my application basically follows this workflow:
    1. Open a LAS file.
    2. Do some stuff with ALL of the points.
    3. Save a new LAS file.
    4. Repeat 1-3 through a directory.
    The question is whether processing the last point in the set requires you to know the first point in the set. If not then you don't need to pre-read every point to memory, you can load just those you need and then forget them before you load a next portion of points.

    Frankly, I don't even know where to begin when it comes to designing a tree-based structure for this dataset. I'm interested in learning more.
    For example, since your data are points (x, y records) a simple optimisation would be to store the x value in a node and all y values for that point in children of that node. The more x values repeat, the more benefit it brings you.

    Another approach would be to calculate groups of points that are close to each other, store the mean position in a node and deltas to each point in child nodes (since deltas will contain much smaller values, they can be stored using less memory). This allows you to dump all the child nodes to disk, keeping just their parent and when the parent is asked to give back its child nodes, you can load them back to memory, potentially swaping some other group of points to storage.

    These are just ideas, the optimal approach depends on HOW you use your data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #8
    Join Date
    Jan 2011
    Posts
    70
    Thanks
    43
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Convert QLinkedList to QList

    Quote Originally Posted by ChrisW67 View Post
    The "best" solution could very much depend on exactly what stuff you are doing to all the points in the LAS file. Your options might also be different if the LAS file has fixed record sizes. For example, there are methods for sorting huge files without loading the entire file into memory. See http://en.wikipedia.org/wiki/External_sorting
    Quote Originally Posted by wysota View Post
    Another approach would be to calculate groups of points that are close to each other, store the mean position in a node and deltas to each point in child nodes (since deltas will contain much smaller values, they can be stored using less memory). This allows you to dump all the child nodes to disk, keeping just their parent and when the parent is asked to give back its child nodes, you can load them back to memory, potentially swaping some other group of points to storage.
    Fascinating ideas! I'm definitely going to look into some sort of external cache system soon, so I love both ideas conceptually. Thanks for giving me a direction to go with this!

Similar Threads

  1. Replies: 4
    Last Post: 20th August 2010, 13:54
  2. Replies: 1
    Last Post: 24th July 2010, 17:23
  3. QVector, QLinkedList
    By aash_89 in forum Qt Programming
    Replies: 2
    Last Post: 22nd July 2010, 02:20
  4. QList or QLinkedList
    By eleanor in forum Newbie
    Replies: 6
    Last Post: 9th November 2007, 09:40
  5. QLinkedList and iterators
    By eu.x in forum Newbie
    Replies: 1
    Last Post: 19th April 2007, 19:38

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.