473,395 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

STL Map of Pointers vs Map Containing the Data

My application consists of the following requirements:

1. The map container will be created in full at the start of the app and no insertions or deletions will occur throughout the life of the object.

2. Updates to data elements inside the map occur frequently.

3. Access to map "records" will need to be by key at times and at other times access will be sequential, starting from the first "record" and continuing thru to the last "record".

4. The container is large - in excess of 1gb, with many "records", whose data elements add up to about 65 bytes, with the key element about 24 bytes in length.

My question is whether there is a significant performance difference between the two models, one model being having the key and data all contained literally inside the map object versus the other model of constructing a map of pointers to a list or array that contains the data?

Also, in the application I have put forward, if anyone has a better solution than the STL map, perhaps a hybrid solution of some sort, I am open to suggestions.

Thanks,

Nukerdoggie
Aug 28 '07 #1
6 7216
RRick
463 Expert 256MB
The pointer approach will add an extra 4 or 8 bytes for each record of the data. This is an increase of either 6% or 12% to your program data size. You also have the extra work of newing and deleting the data.

Storing the data internally is fine except for modifications to the data. In this case you must copy the data to and from the map. At 65 bytes, its not too bad, but that is 8 or 16 times longer than copying a pointer.

Which is best? I don't see any clear winner here.


As for using an STL map, that's pretty much a given from your description. When you say key, element, and infer random access; that defines a map. My only caution is that maps can get slow when they get big, especially with insertions. Watch the creation of the map and see if it slows down with more and more additions. When insertions start to slow down, it only gets worst. It looks like you have a million entries and that could cause problems. Big, sloooowwww problems.

If you need other structures, then a vector will work. Concatenate the key with the data, insert at the end, and sort on the key value. This allows you to search sequentially and also do a binary search on the key. I believe the STL has algorithms that will sort and search for you.
Aug 28 '07 #2
Thanks for the quick reply - your insights are very helpful, RRick.
Aug 28 '07 #3
RRick
463 Expert 256MB
Feel free to reply to this posting when you get some results.

We all would be interested in knowing if there are performance issues to STL maps with a million inserts.

Good Luck
Aug 28 '07 #4
Will do..... The app runs on a fast Linux server and should be quite speedy by comparison to Windows.
Aug 29 '07 #5
Here are the results of our testing:

We created a STD::STL test map with a 64-byte key and a 256-byte data section, with all data consolidated into the map (it was not a map of pointers to the data).

Our first run created a map of just over 800,000 records and the total elapsed time to create the map was about 8 seconds.

Our second run created the same map structure, but this time with 1.8 million records. The total elapsed time to create the map was about 18 seconds.

This test is very encouraging and demonstrates for us that the creation of the map (insert perfomance) is very fast, well within the framework of required perfomance, even when the number of inserts gets very large.

The development server we ran the test on is an x86 4-processor Sun server with AMD chips running at 2.4GHZ each, Linux opsys, with about 60 developer-tester/users logged on at the time we ran the test.
Aug 29 '07 #6
RRick
463 Expert 256MB
Thanks for the info.

Your measurements are linear that's about as good as can be expected. Also, its good to know that maps can handle a million plus entries without issues.

Good Luck.
Aug 31 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Web Developer | last post by:
Hi, Can someone provide a short and concise statement(s) on the difference between pointers and references. A graphical representation (via links?) of both would be much appreciated as well. ...
1
by: Darren | last post by:
hi, i'm trying to write some code to generate seperate files with the name of a call number, and containing the call data, from one big file containing all data. but when i run it, i get the...
19
by: Thomas Matthews | last post by:
Hi, Given a structure of pointers: struct Example_Struct { unsigned char * ptr_buffer; unsigned int * ptr_numbers; }; And a function that will accept the structure:
4
by: Konstantin Shemyak | last post by:
I have a big structure tree. All leaves are scalar values (no pointers). Present are arrays, structures and unions. I want to be able to store/read the content of the structure in/from a file, and...
8
by: Gerald | last post by:
I have a problem with an array of pointers. In a program I'm writing, I have to read a file, containing thousands of short lines. The content of another file will be compared against each line...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
8
by: Steve Lambert | last post by:
Hi, I'd be grateful if someone could clarify this for me. In the linked list structure my intention is to declare an array of length 3 containing pointers to node eg. Node *Iterators The...
59
by: MotoK | last post by:
Hi Experts, I've just joined this group and want to know something: Is there something similar to smart pointers in C or something to prevent memory leakages in C programs. Regards MotoK
11
by: desktop | last post by:
I have made this example: #include<iostream> class Beer { public: Beer() { std::cout << "made a beer\n"; num = 1; }
1
by: Sam | last post by:
Hi there. I hope this code is standard C. I think it is. Anyway, I haven't used C in a Looooooong time and am a little rusty on pointers. I am wondering why "buff" is a pointer to a pointer...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.