473,327 Members | 1,997 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,327 software developers and data experts.

Vector of STL maps versus Vector of objects

I am using a vector of maps to store a sequence of key-value pairs. I
fear usage of an STL map would lead to serious memory bottlenecks.
Instead I was thinking of using an object to store key-value mappings.

class StringPair
{
char *key;
char *value;
};
I can now store objects of class StringPair rather than maps in the
vector. Is this a feasible option from performance considerations (i
mean memory usage & efficiency of inserts,updates & deletes) ?

Jul 26 '05 #1
2 7375
am*****@gmail.com wrote:
I am using a vector of maps to store a sequence of key-value pairs. I
fear usage of an STL map would lead to serious memory bottlenecks.
Instead I was thinking of using an object to store key-value mappings.

class StringPair
{
char *key;
char *value;
};
I can now store objects of class StringPair rather than maps in the
vector. Is this a feasible option from performance considerations (i
mean memory usage & efficiency of inserts,updates & deletes) ?


Certainly using a map just to store a single key/value pair is not what
you want to be doing. I would suggest a vector of std::pair (which is
the value_type of map, by the way).

Your "StringPair" class may have a problem, depending on how exactly you
intend to use it. Who allocates the strings you are storing? Who frees
that memory? Maybe you have all that worked out already. If not, save
yourself the headache and use std::string. Example:

#include <vector>
#include <string>
#include <utility>
std::vector< std::pair<std::string, std::string> > v ;

// ...

v.push_back(std::make_pair("key1", "value1")) ;
v.push_back(std::make_pair("key2", "value2")) ;
-Alan
Jul 26 '05 #2
Ian
am*****@gmail.com wrote:
I am using a vector of maps to store a sequence of key-value pairs. I
fear usage of an STL map would lead to serious memory bottlenecks.
Instead I was thinking of using an object to store key-value mappings.
Why? Try it and see, don't optimise before you have to.

Ian
class StringPair
{
char *key;
char *value;
};
I can now store objects of class StringPair rather than maps in the
vector. Is this a feasible option from performance considerations (i
mean memory usage & efficiency of inserts,updates & deletes) ?

Jul 26 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bo Peng | last post by:
Dear List, I have had success in using vector.i of SWIG to map between c++: foo(vector<int>) python: foo() However, the map of vector of objects fails: c++: foo(vector<obj> )
7
by: deancoo | last post by:
Ok, I've got a vector I've filled with a LOT of data, and after massaging it just right, I need to copy it all over to a map where I'll have the advantage of assigning a custom key as the key...
1
by: juvi | last post by:
Hi, is there a tool for Vector Graphics Maps creation? (maybe a free version?) If yes: Can I use the created map with Microsoft MapPoint? Would it be possible to create a map of a building and...
9
by: kathy | last post by:
I am using std::vector in my program: func() { std::vector <CMyClass *> vpMyClass; vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new...
9
by: Jeff | last post by:
Hello- Ive never used a vector or vectors in C++ so I have a question for you all. I know I can dynamically create the size I need upfront, but is it possible to create them on the fly...
13
by: zaineb | last post by:
Hi, This is a follow-up of sort of this thread:...
4
by: nw | last post by:
Hi All, I currently have a vector of objects (lets call them MyObject). I want to perform various operations regularly on the whole vector, for example find the maximum, average, or operations...
16
by: xyz | last post by:
I have to run the simulation of a trace file around (7gb contains 116million entries)... presently i am using vector iterators to check the conditions in my program..... it is taking 2 days to...
10
by: oktayarslan | last post by:
Hi all; I have a problem when inserting an element to a vector. All I want is reading some data from a file and putting them into a vector. But the program is crashing after pushing a data which...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.