Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Fastest way to ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 9 Topic 9561 of 9593
Post > Topic >>

Fastest way to clone a hash_map

by devdude <rottyguy70@[EMAIL PROTECTED] > Apr 29, 2008 at 12:09 PM

Hi,

I have the need to take a snapshot of a hash_map during execution
(actually transform it to a vector).  This map is a shared resource
and therefore must be locked prior to any read/write operations thus I
need to minimize the amount of time the map resource is locked.

The map is defined as type <string, boost::shared_ptr<myobject>>.  My
algorithm is as such:

void SnapShotToVector( vector< pair< string,
boost::shared_ptr<myobject> >& vec )
{

    lockResource(this->map);
    vec.resize( map.size() );
    copy(this->map.begin(), this->map.end(),list.begin());
    unlockResource(this->map);
}

For about 3M elements w/in the map, I'm noticing that the resize op
takes about 150ms and the copy takes ~850ms.  Is there any way to do
better? I suppose the total time doesn' t matter as it's the time the
resource is actually locked is the primary concern.

TIA

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]




 9 Posts in Topic:
Fastest way to clone a hash_map
devdude <rottyguy70@[E  2008-04-29 12:09:16 
Re: Fastest way to clone a hash_map
=?ISO-8859-1?Q?Daniel_Kr=  2008-04-29 17:42:35 
Re: Fastest way to clone a hash_map
"Stephen Howe"   2008-04-29 17:43:43 
Re: Fastest way to clone a hash_map
bachlipp@[EMAIL PROTECTED  2008-04-29 17:42:01 
Re: Fastest way to clone a hash_map
Tony Delroy <tony_in_d  2008-04-30 03:52:18 
Re: Fastest way to clone a hash_map
devdude <rottyguy70@[E  2008-04-30 04:13:33 
Re: Fastest way to clone a hash_map
Carl Barron <cbarron41  2008-04-30 04:13:32 
Re: Fastest way to clone a hash_map
Mathias Gaunard <loufo  2008-04-30 04:13:32 
Re: Fastest way to clone a hash_map
"Roman.Perepelitsa@[  2008-04-30 10:27:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 2:31:32 CDT 2008.