From: Goran on 19 Apr 2010 03:57 On Apr 19, 12:02 am, �� Tiib <oot...(a)hot.ee> wrote: > CoW is underlying mechanics of lazy copying. It copies only when > someone writes into one of copies. It is odd that people claim it > contradicts with threads. Ah, but it does. Here's the problem: if you want to use CoW inter- thread, the detection of forking must be done in a thread-safe manner. This typically involves test-and-set instruction. That is quite heavy on the hardware cache that it is possible, under heavy inter-thread use, that just making a copy outperforms CoW. See http://www.gotw.ca/publications/optimizations.htm for a nice better analysis. Goran. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Alexander Terekhov on 22 Apr 2010 08:23 Francis Glassborow wrote: [...] > CoW tries to delay the decision but that delay is not cost free. CoW is basically atomic increments versus heap allocations + copying and atomic decrements versus heap deallocations. Absent 'small' optimizations, CoW wins unless heap allocations+copying/deallocations cost less than atomic increment/decrement. The problem of CoW in C++ (and other similar languages) is that the C++'s objects are treated by default as mutable/not const, hence the problem of unsharing for functions like [](), except for const objects. The cure: refer to objects via const & (unless you really want to modify) and CoW STL will fly! regards, alexander. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Francis Glassborow on 22 Apr 2010 21:57 Alexander Terekhov wrote: > Francis Glassborow wrote: > [...] >> CoW tries to delay the decision but that delay is not cost free. > > CoW is basically atomic increments versus heap allocations + copying and > atomic decrements versus heap deallocations. Absent 'small' > optimizations, CoW wins unless heap allocations+copying/deallocations > cost less than atomic increment/decrement. The problem of CoW in C++ > (and other similar languages) is that the C++'s objects are treated by > default as mutable/not const, hence the problem of unsharing for > functions like [](), except for const objects. The cure: refer to > objects via const & (unless you really want to modify) and CoW STL will > fly! > > regards, > alexander. > Fine as long as the object is immutable but it only takes a single possible mutate to lose the advantage when dealing with concurrency rather than just multi-threading. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Maxim Yegorushkin on 22 Apr 2010 22:15 On 20/04/10 15:37, Mathias Gaunard wrote: > On 18 avr, 23:02, Öö Tiib<oot...(a)hot.ee> wrote: > >> For example POSIX fork() >> implementations are usually cheap thanks to CoW. > > Rather, the fork+execvp pattern requires COW with delayed allocation > (overcommit) to be efficient in both speed and memory usage. And > overcommit is obviously a serious problem that completely breaks the C > and C++ languages. Interesting that you would mention overcommit as a serious problem. It is a tunable feature and can be turned on and off. Can't remember though if I ever needed to turn it off. -- Max [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Mathias Gaunard on 20 Apr 2010 16:14
On 20 avr, 20:42, �� Tiib <oot...(a)hot.ee> wrote: > Interesting. How it breaks C and C++ completely? By having malloc or new return a pointer to some memory that has not yet been allocated, and thus accessing it later may result in a crash, instead of returning null or throwing an exception. > On the other hand trying to achieve same > effect on Windows using CreateProcess is very inefficent and resource- > consuming. Huh? On the contrary, CreateProcess is more efficient, it's just that the function needs to have a lot of parameters to do as many things. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |