Results 1 to 6 of 6

Thread: Fastest data structure to store large no of coordinate points

  1. #1
    Join Date
    Dec 2012
    Posts
    45
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Fastest data structure to store large no of coordinate points

    I am developing an application in which i have to calculate large no of X and Y coordinate points and and have to plot them. For this i used QVector, but now the problem is that time taken in inserting values in vector is very large , so can any body tell me a fast and reliable data structure

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Fastest data structure to store large no of coordinate points

    use QList .It does not store objects directly, but instead stores pointers to them. You gain all the benefits of quick insertions at both ends, and reallocations involve shuffling pointers .very fast since memory is preallocated at both ends of the internal array .
    Note: if u run ur code in Debug mode QVector will be always slower ..
    "Behind every great fortune lies a crime" - Balzac

  3. #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: Fastest data structure to store large no of coordinate points

    Quote Originally Posted by shivendra46d View Post
    For this i used QVector, but now the problem is that time taken in inserting values in vector is very large , so can any body tell me a fast and reliable data structure
    QVector is fine. If you know the number of points before you start you can call QVector::resize() once only. You incur only a single memory allocation and construction, rather than multiples as you grow the vector. Access is then random and does not involve memory reallocations.

    If you have an idea of the maximum size then call reserve() once and grow the vector only by appending. This avoids memory reallocations.

    If you are inserting in the middle then QVector is not right for you (or your algorithm should be rethought).

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

    wagmare (3rd December 2013)

  5. #4
    Join Date
    Dec 2012
    Posts
    45
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Fastest data structure to store large no of coordinate points

    no i dont have to insert any thing in middle all my values are to be continuous, and i dont know the maximum size of the vector, and yes i am using append ins ted of insert. I dont want to use threads is there any other data structures available for faster execution or my choice is correct ?

  6. #5
    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: Fastest data structure to store large no of coordinate points

    If you don't know any maximum number of elements then use QList as wagmare already suggested.

    Not sure why you bring up threads though.

    Cheers,
    _

  7. #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: Fastest data structure to store large no of coordinate points

    I dont want to use threads
    Threads? Nothing to do with it.
    is there any other data structures available for faster execution or my choice is correct ?
    There is little faster than a directly indexed, contiguous block of memory like QVector. If you do not know the precise size ahead of schedule but can take a educated guess then use that in reserve().

    Rather than fixate on a data structure panacea why not do the work to isolate exactly where your algorithm and storage are really spending most of their time. Then you have some idea what it is you are trying to optimise.

Similar Threads

  1. fastest way to read large files (with mixed content)
    By timmu in forum Qt Programming
    Replies: 8
    Last Post: 10th September 2012, 10:09
  2. Fastest way to transfer Data over tcp
    By Qiieha in forum General Programming
    Replies: 21
    Last Post: 29th July 2012, 18:11
  3. Replies: 2
    Last Post: 12th May 2011, 07:30
  4. Replies: 1
    Last Post: 10th November 2010, 06:32
  5. Replies: 1
    Last Post: 17th July 2009, 08:22

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.