LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-13-2012, 07:24 AM   #1
mazel
LQ Newbie
 
Registered: Jul 2012
Posts: 12

Rep: Reputation: Disabled
Fastest container in random access?


Hello all,
Im developping an C++ application for a target system with limited resources and now Im facing some performance issues with accessing some values stored in vector.

Is there any better container than vector to store these values and access them randomly e.g. by its index?

Any advices are welcomed ...
 
Old 09-13-2012, 08:17 AM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Take a look at std::map

Here is an example using map.find:
http://www.cplusplus.com/reference/stl/map/find/
 
Old 09-13-2012, 08:45 AM   #3
mazel
LQ Newbie
 
Registered: Jul 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Map / Vector

Recently found realy helpful container decesion chart (in attachments).

and Ive read some articles and forums and found... eg:

Quote:
Firstly, finding an item in a very small vector can easily be faster than the same thing in a map, because all the memory in a vector is always contiguous (and so plays more nicely with computers' caches and such things), and the number of comparisons needed to find something in a vector might be about the same as for a map. Finding an element in a map needs fewer operations in the limit of very large containers.

The point where maps become faster than vectors depends on the implementation, on your processor, what data is in the map, and subtle things like what memory is in the processor's cache. Typically, the point where map becomes faster would be about 5-30 elements.
Ill try the map instead and hope that it will be faster, vector is definatelly not for my use ... so it at least worth to try...

Thanks very much.
Attached Thumbnails
Click image for larger version

Name:	containerchoice.png
Views:	19
Size:	8.6 KB
ID:	10674  
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] random file access from C caverdave Programming 6 07-10-2009 10:35 AM
random access writes to compressed files pelkeyj Programming 5 03-31-2008 04:01 PM
C++ coding style question re: random access iterators spursrule Programming 10 03-03-2008 09:21 PM
Strange file behavor using random access in C exvor Programming 4 05-19-2006 12:23 PM
C++ text stream random access Orkie Programming 6 10-26-2005 02:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration