map<,> optimization question

M

mcassiani

Hi,



I need use map faster as possible (I store in the map data about open
network connections).



First a question, this code fragment is from "The C++ Programming........
3rd edition by B. Stroustrup"



m[k] is equivalent to (*(m.insert(make_pair(k,V()))).first)).second



The work of V() is to create a void base tape? if so, the expression:





m.insert(make_pair(k,objItem))



where objItem is my object is a better choice?



thanks

Marco C.
 
V

Victor Bazarov

mcassiani said:
I need use map faster as possible (I store in the map data about open
network connections).

First a question, this code fragment is from "The C++ Programming........
3rd edition by B. Stroustrup"

m[k] is equivalent to (*(m.insert(make_pair(k,V()))).first)).second

The work of V() is to create a void base tape? if so, the expression:
Right.

m.insert(make_pair(k,objItem))

where objItem is my object is a better choice?

Could be. You won't know until you actually put it into the working
program and run it under a profiler. Speculation costs very little and
has no real value. Get results from timing your process, then judge.

V
 
M

msalters

mcassiani said:
Hi,

I need use map faster as possible (I store in the map data about open
network connections).

These days, memory tends to be a lot faster than I/O. Usually, the
overhead of map will be insignificant. Just make sure the objects in
the map don't perform too much I/O - i.e. cheap default ctors.

HTH,
Michiel Salters
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top