copy-on-write

Why is there no boost::copy_on_write_ptr?

末鹿安然 提交于 2019-12-04 22:20:50
问题 I just saw this nice copy-on-write pointer implementation. It looks pretty generic and useful, so my question is: Is such a class contained in any of the C++ toolkits (boost, loki, etc.)? If not, I'd really like to know why because it is a really useful idiom and apparently a generic implementation seems doable (like the one I linked to). 回答1: There was a lot of debate over the possibility, and at least one suggested version of what eventually came out as auto_ptr was for a reference counted

Multiprocessing: why is a numpy array shared with the child processes, while a list is copied?

烂漫一生 提交于 2019-12-04 12:52:25
I used this script (see code at the end) to assess whether a global object is shared or copied when the parent process is forked. Briefly, the script creates a global data object, and the child processes iterate over data . The script also monitors the memory usage to assess whether the object was copied in the child processes. Here are the results: data = np.ones((N,N)) . Operation in the child process: data.sum() . Result: data is shared (no copy) data = list(range(pow(10, 8))) . Operation in the child process: sum(data) . Result: data is copied . data = list(range(pow(10, 8))) . Operation

How to Disable Copy-on-write and zero filled on demand for mmap()

笑着哭i 提交于 2019-12-04 05:22:53
I am implementing cp(file copy) command using mmap(). For that I mapped the source file in MAP_PRIVATE (As I just want to read)mode and destination file in MAP_SHARED mode(As I have to writeback the changed content of destination file). While doing this I have observed performance penalty due to lots of minor page faults that occurs due to 2 reason. 1) Zero fill on demand while calling mmap(MAP_PRIVATE) for source file. 2) Copy on write while calling mmap(MAP_SHARED) for destination file. Is there any way to disable Zero-fill-on-demand and Copy-on-write ? Thanks, Harish There is MMAP_POPULATE

Why is COW std::string optimization still enabled in GCC 5.1?

房东的猫 提交于 2019-12-04 03:31:22
问题 According to GCC 5 release changes page (https://gcc.gnu.org/gcc-5/changes.html): A new implementation of std::string is enabled by default, using the small string optimization instead of copy-on-write reference counting I decided to check it and wrote a simple program: int main() { std::string x{"blah"}; std::string y = x; printf("0x%X\n", x.c_str()); printf("0x%X\n", y.c_str()); x[0] = 'c'; printf("0x%X\n", x.c_str()); printf("0x%X\n", y.c_str()); } And the result is: 0x162FC38 0x162FC38

Garbage collector in Ruby 2.2 provokes unexpected CoW

旧城冷巷雨未停 提交于 2019-12-04 00:46:23
问题 How do I prevent the GC from provoking copy-on-write, when I fork my process ? I have recently been analyzing the garbage collector's behavior in Ruby, due to some memory issues that I encountered in my program (I run out of memory on my 60core 0.5Tb machine even for fairly small tasks). For me this really limits the usefulness of ruby for running programs on multicore servers. I would like to present my experiments and results here. The issue arises when the garbage collector runs during

Why is there no boost::copy_on_write_ptr?

时光怂恿深爱的人放手 提交于 2019-12-03 14:37:54
I just saw this nice copy-on-write pointer implementation. It looks pretty generic and useful, so my question is: Is such a class contained in any of the C++ toolkits (boost, loki, etc.)? If not, I'd really like to know why because it is a really useful idiom and apparently a generic implementation seems doable (like the one I linked to). There was a lot of debate over the possibility, and at least one suggested version of what eventually came out as auto_ptr was for a reference counted COW pointer. Unfortunately, the time for COW has mostly passed. Making a COW pointer (or COW-whatever)

Programmatically determine if std::string uses Copy-On-Write (COW) mechanism

荒凉一梦 提交于 2019-12-03 08:32:23
Following up on the discussion from this question , I was wondering how does one using native C++ determine programmatically whether or not the std::string implementation they are using utilizes Copy-On-Write (COW) I have the following function: #include <iostream> #include <string> bool stdstring_supports_cow() { //make sure the string is longer than the size of potential //implementation of small-string. std::string s1 = "012345678901234567890123456789" "012345678901234567890123456789" "012345678901234567890123456789" "012345678901234567890123456789" "012345678901234567890123456789"; std:

Which string classes to use in C++?

£可爱£侵袭症+ 提交于 2019-12-03 07:08:16
问题 we have a multi-threaded desktop application in C++ (MFC). Currently developers use either CString or std::string, probably depending on their mood. So we'd like to choose a single implementation (probably something other than those two). MFC's CString is based on copy-on-write (COW) idiom, and some people would claim this is unacceptable in a multithreaded environment (and probably reference to this article). I am not convinced by such claims, as atomic counters seem to be quite fast, and

Which string classes to use in C++?

微笑、不失礼 提交于 2019-12-02 20:42:35
we have a multi-threaded desktop application in C++ (MFC). Currently developers use either CString or std::string, probably depending on their mood. So we'd like to choose a single implementation (probably something other than those two). MFC's CString is based on copy-on-write (COW) idiom, and some people would claim this is unacceptable in a multithreaded environment (and probably reference to this article ). I am not convinced by such claims, as atomic counters seem to be quite fast, and also this overhead is somehow compensated by a reduction in memory re-allocations. I learned that std:

How does copy-on-write work in fork-exec? [closed]

帅比萌擦擦* 提交于 2019-12-02 19:36:00
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . A process fork s a child process, and calls exec() in the child process. With copy-on-write, after fork the parent process and child process share the memory. When the child process calls exec() to load another process, will Linux copy the parent memory to the new memory and the child loads another process also