Questions tagged [copy-on-write]
215 questions
13
votes
1 answer
In place modification of matrices in R
I there any way to avoid copy-on-modify for in-place modifications of matrices in R?
I am trying to copy a smaller matrix to a slice of larger matrix as follows.
library(data.table)
y <- matrix(c(11,21,31,12,22,32),nrow=3,ncol=2)
address(y)
[1]…

Crops
- 5,024
- 5
- 38
- 65
12
votes
2 answers
Will copy-on-write prevent data duplication on arrays?
I am programming a web API client in PHP that parses CSV data into associative arrays and I want to protect my users from data-duplication when using these arrays.
My users will never be writing to these arrays (theoretically they could but it makes…

thwd
- 23,956
- 8
- 74
- 108
12
votes
1 answer
Get the copy-on-write behaviour of fork()ing, without fork()
I have a large buffer:
char *buf = malloc(1000000000); // 1GB
If I forked a new process, it would have a buf which shared memory with the parent's buf until one or the other wrote to it. Even then, only one new 4KiB block would need to be…

fadedbee
- 42,671
- 44
- 178
- 308
11
votes
1 answer
How to prove "copy-on-write" on String type in Swift
As the title said, I tried to prove myself that COW(copy on write) is supported for String in Swift. But I cannot find a proof. I proved the COW on Array and Dictionary after trying the following codes:
func address(of object: UnsafeRawPointer) ->…

Wu_
- 145
- 7
11
votes
2 answers
Copy-on-write support in STL
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…

Septagram
- 9,425
- 13
- 50
- 81
10
votes
2 answers
Why the address of variable of child process and parent process is same
Here is my code
int main()
{
pid_t pid;
int y = 3;
if ( (pid = fork()) <0 )
return -1;;
if( pid == 0 ) /* child */
{
printf(" before: %d %p\n", y, &y );
y *= 10;
printf("after: %d %p\n", y, &y );
}
else /* father */
…

Janus.Le
- 241
- 4
- 12
10
votes
1 answer
Garbage collector in Ruby 2.2 provokes unexpected CoW
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…

Thomas Kalmus
- 111
- 5
10
votes
2 answers
How does copy-on-write work in fork()?
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…

Min Fu
- 789
- 1
- 6
- 16
10
votes
2 answers
How does copy-on-write in fork() handle multiple fork?
According to wikipedia (which could be wrong)
When a fork() system call is issued, a copy of all the pages corresponding to the parent process is created, loaded into a separate memory location by the OS for the child process. But this is not…

ssgao
- 5,151
- 6
- 36
- 52
9
votes
1 answer
macOS with APFS: Copy-On-Write in Terminal
I am writing some little script that assembles backup data into one directory. The directory content will then be uploaded to a cloud service and after that we can remove it. I was wondering how one could utilize APFS' copy-on-write feature with a…

Anticro
- 685
- 4
- 12
9
votes
5 answers
In Java can I depend on reference assignment being atomic to implement copy on write?
If I have an unsynchronized java collection in a multithreaded environment, and I don't want to force readers of the collection to synchronize[1], is a solution where I synchronize the writers and use the atomicity of reference assignment feasible?…

MilesHampson
- 2,069
- 24
- 43
8
votes
2 answers
Confusion about Copy-On-Write and shared_ptr
I have searched the web and read through the Boost documentation about shared_ptr. There is a response on SO that says that shared_ptr for Copy-On-Write (COW) sucks and that TR! has removed it from the string libraries. Most advice on SO says to…

Thomas Matthews
- 56,849
- 17
- 98
- 154
8
votes
1 answer
Which value types in Swift supports copy-on-write?
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…

SwiftyFinch
- 445
- 2
- 12
8
votes
6 answers
How to know whether a copy-on-write page is an actual copy?
When I create a copy-on-write mapping (a MAP_PRIVATE) using mmap, then some pages of this mapping will be copied as soon as I write to specific addresses. At a certain point in my program I would like to figure out which pages have actually been…
user458577
8
votes
2 answers
Qt undocumented method setSharable
I stumbled about a method which seems to be present in all data objects like QList, QQueue, QHash...
I even investigated so far I can see the source code of it, which is
inline void setSharable(bool sharable) {
if (!sharable) detach();…

drahnr
- 6,782
- 5
- 48
- 75