copy-on-write

Overriding equals for CopyOnWriteArraySet.add and remove

大兔子大兔子 提交于 2019-12-02 14:58:14
问题 I have classes like below class A { @Override public boolean equals(Object other) { return true } } Class B extends A { } Class C extends A { @Override public boolean equals(Object other) { if ((other != null) || (other instanceOf B)) return false; } } In my main() I have this following code Set<A> mySet = new CopyOnWriteArraySet<A>(); mySet.add(C); I want mySet to contain C at this point mySet.add(B); // #1 I want mySet to contain C & B at this point mySet.remove(B); // #2 I want mySet to

Overriding equals for CopyOnWriteArraySet.add and remove

我们两清 提交于 2019-12-02 08:20:39
I have classes like below class A { @Override public boolean equals(Object other) { return true } } Class B extends A { } Class C extends A { @Override public boolean equals(Object other) { if ((other != null) || (other instanceOf B)) return false; } } In my main() I have this following code Set<A> mySet = new CopyOnWriteArraySet<A>(); mySet.add(C); I want mySet to contain C at this point mySet.add(B); // #1 I want mySet to contain C & B at this point mySet.remove(B); // #2 I want mySet to contain C at this point I want to create a global queue where if object C exists in the queue B should be

Which value types in Swift supports copy-on-write?

旧时模样 提交于 2019-12-01 04:33:55
I read about copy-on-write implementation for Array in Swift here . Arrays, like all variable-size collections in the standard library, use copy-on-write optimization. Multiple copies of an array share the same storage until you modify one of the copies. When that happens, the array being modified replaces its storage with a uniquely owned copy of itself, which is then modified in place. Optimizations are sometimes applied that can reduce the amount of copying. I was wondering if you have any information about which structure supports copy-on-write. Copy-on write is supported for String and

Garbage collector in Ruby 2.2 provokes unexpected CoW

狂风中的少年 提交于 2019-12-01 03:14:27
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 forking. I have investigated three cases that illustrate the issue. Case 1: We allocate a lot of objects

Copy-on-write support in STL

自古美人都是妖i 提交于 2019-11-30 16:55:22
问题 I was just reading a Wikipedia article on Copy-on-write (curious if there are any filesystems that support it), and was surprised by the following passage: COW is also used outside the kernel, in library, application and system code. The string class provided by the C++ standard library, for example, was specifically designed to allow copy-on-write implementations: std::string x("Hello"); std::string y = x; // x and y use the same buffer y += ", World!"; // now y uses a different buffer // x

How does copy-on-write work in fork()?

…衆ロ難τιáo~ 提交于 2019-11-30 13:59:56
I want to know how copy-on-write happens in fork(). Assuming we have a process A that has a dynamical int array: int *array = malloc(1000000*sizeof(int)); Elements in array are initialized to some meaningful values. Then, we use fork() to create a child process, namely B. B will iterate the array and do some calculations: for(a in array){ a = a+1; } I know B will not copy the entire array immediately, but when does the child B allocate memory for array? during fork()? Does it allocate the entire array all at once, or only a single integer for a = a+1 ? a = a+1; how does this happen? Does B

How to implement Copy-on-Write?

女生的网名这么多〃 提交于 2019-11-30 12:00:28
问题 I want to implement a copy-on-write on my custom C++ String class, and I wonder how to... I tried to implement some options, but they all turned out very inefficient. Thank you guys :-) 回答1: In a multi-threaded environemnt (which is most of them nowadays) CoW is frequently a huge performance hit rather than a gain. And with careful use of const references, it's not much of a performance gain even in a single threaded environment. This old DDJ article explains just how bad CoW can be in a

Does StringBuilder become immutable after a call to ToString?

这一生的挚爱 提交于 2019-11-30 11:26:37
I distinctly remember from the early days of .NET that calling ToString on a StringBuilder used to provide the new string object (to be returned) with the internal char buffer used by StringBuilder. This way if you constructed a huge string using StringBuilder, calling ToString didn't have to copy it. In doing that, the StringBuilder had to prevent any additional changes to the buffer, because it was now used by an immutable string. As a result the StringBuilder would switch to a "copy-on-change" made where any attempted change would first create a new buffer, copy the content of the old

remove elements from CopyOnWriteArrayList

纵饮孤独 提交于 2019-11-30 05:02:22
I am getting an exception when I try to remove elements from CopyOnWriteArrayList using an iterator. I have noticed that it is documented Element-changing operations on iterators themselves (remove, set, and add) are not supported. These methods throw UnsupportedOperationException. (from http://download.oracle.com/javase/6/docs/api/java/util/concurrent/CopyOnWriteArrayList.html ) Now, surprisingly i can iterate it with foreach and use the remove() function . But then I get the famous bug - when trying to remove an item from a list using a for loop - you skip the element next to the removed

Does StringBuilder become immutable after a call to ToString?

风流意气都作罢 提交于 2019-11-29 17:00:38
问题 I distinctly remember from the early days of .NET that calling ToString on a StringBuilder used to provide the new string object (to be returned) with the internal char buffer used by StringBuilder. This way if you constructed a huge string using StringBuilder, calling ToString didn't have to copy it. In doing that, the StringBuilder had to prevent any additional changes to the buffer, because it was now used by an immutable string. As a result the StringBuilder would switch to a "copy-on