Talk About Network

Google


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 > Re: Fastest way...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 9 Topic 9561 of 9831
Post > Topic >>

Re: Fastest way to clone a hash_map

by devdude <rottyguy70@[EMAIL PROTECTED] > Apr 30, 2008 at 04:13 AM

Hi Everyone, thanks for the responses.  A few things:

1) I am currently using r/w locks (and are implemented through
automatic objects so destruction is guaranteed) but the numbers came
from stress testing all writes so it doesn't make much of a difference
in this case.  That said, are there any standard r/w lock impls that
people are using (my current platform is Windows).

2) Total time doesn't really matter because this function will be done
in a background thread.  Obviously it can't take hours but several
seconds are acceptable if lock time were, say 10ms or better.

3) I'm currently using google's dense_map for this impl.

4) What I'm really after is to be able to sort the hash_map (in real
time) so I can prune it based on a given criteria (think cache
scavenging).  I suspect the best way is to snap_shot the data and work
on the copy, but perhaps there's a better way.

5) Are there any usable strategies that could iterate the map multiple
times, locking minimally per iteration, to produce the desired
effects?

> Three things came to my mind:
>
> * You could try:
> lockResource(map);
> const std::map<[...]>::size_type sz(map.size());
> unlockResource(map);
> vec.reserve( sz );
> lockResource(map);
> vec.insert(vec.end(),map.begin(),map.end());
> unlockResource(map);
>
> I.e. factoring the allocation out of the critical section. It does not
> really matter above, whether the map changed its size inbetween the
> two guarded sections. Note that here "std::vector<>::reserve()" is
> used instead of "std::vector<>::resize()" in your code. Therefore I
> must use an insertion command that adapts the size, so "std::copy<>()"
> won't do anymore. Please note, however, that you may win less than it
> seems at first sight because memory allocation on freestore implies
> locking - go for malloc implementations that are optimized for this
> case.
>
> * If you do not need consistency in time you could go for a (non
> standard) container that sup****ts fine grained locking instead the
> above coarse grained approach: Read e.g. the PhD thesis pointed to at
> <http://www.freidok.uni-freiburg.de/volltexte/41/>
> about red / black trees in concurrent applications (in German only).
> So given your container sup****ts a robust iterator, your "copy" could
> contains the contents of the map as seen by the iterator as it travels
> through the map while the other branches of the map might change in
> parallel. This might not be acceptable for your application, however.
>

Thanks, I'll take a look.


-- 
      [ 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 Sat Jul 26 2:46:35 CDT 2008.