PDA

View Full Version : Fastest data structure to store large no of coordinate points



shivendra46d
3rd December 2013, 05:21
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

wagmare
3rd December 2013, 05:36
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 ..

ChrisW67
3rd December 2013, 06:05
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).

shivendra46d
3rd December 2013, 06:44
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 ?

anda_skoa
3rd December 2013, 10:22
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,
_

ChrisW67
3rd December 2013, 22:41
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.