Questions tagged [copy-on-write]

215 questions
185
votes
9 answers

What is copy-on-write?

I would like to know what copy-on-write is and what it is used for. The term is mentioned several times in the Sun JDK tutorials.
hhafez
  • 38,949
  • 39
  • 113
  • 143
128
votes
7 answers

Legality of COW std::string implementation in C++11

It had been my understanding that copy-on-write is not a viable way to implement a conforming std::string in C++11, but when it came up in discussion recently I found myself unable to directly support that statement. Am I correct that C++11 does not…
acm
  • 12,183
  • 5
  • 39
  • 68
41
votes
2 answers

Does swift copy on write for all structs?

I know that swift will optimize to copy on write for arrays but will it do this for all structs? For example: struct Point { var x:Float = 0 } var p1 = Point() var p2 = p1 //p1 and p2 share the same data under the hood p2.x += 1 //p2 now has its…
gloo
  • 2,490
  • 3
  • 22
  • 38
29
votes
3 answers

Does (string) 'hard-copy' a string?

PHP uses a copy-on-modification system. Does $a = (string) $a; ($a is a already string) modify and copy anything? Especially, this is my problem: Parameter 1 is mixed / I want to allow to pass non-strings and convert them to strings. But sometimes…
mzimmer
  • 523
  • 2
  • 5
  • 11
21
votes
5 answers

How to implement Copy-on-Write?

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.
fiveOthersWaiting
  • 211
  • 1
  • 2
  • 3
20
votes
1 answer

Create copy-on-write directory on Windows 7 with NTFS

I have a directory containing source code, which I compile to produce object files. I want to quickly apply a patch and rebuild in such a way that I have simultaneous access to both the old and new object files. One way to do that is: cd old &&…
Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85
18
votes
2 answers

Copy on Write with shared_ptr

So I have a simple cow_ptr. It looks something like this: template> struct cow_ptr:private Base{ using Base::operator*; using Base::operator->; using Base::operator bool; // etc …
Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
17
votes
7 answers

Which string classes to use in C++?

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…
Roman L
  • 3,006
  • 25
  • 37
16
votes
3 answers

Performance of function slice parameter vs global variable?

I've got the following function: func checkFiles(path string, excludedPatterns []string) { // ... } I'm wondering, since excludedPatterns never changes, should I optimize it by making the var global (and not passing it to the function every…
laurent
  • 88,262
  • 77
  • 290
  • 428
15
votes
9 answers

remove elements from CopyOnWriteArrayList

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…
Bick
  • 17,833
  • 52
  • 146
  • 251
15
votes
1 answer

Python multiprocessing copy-on-write behaving differently between OSX and Ubuntu

I'm trying to share objects between the parent and child process in Python. To play around with the idea, I've created a simple Python script: from multiprocessing import Process from os import getpid import psutil shared =…
15
votes
5 answers

Does StringBuilder become immutable after a call to ToString?

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…
M.S
  • 1,580
  • 1
  • 13
  • 22
14
votes
5 answers

Why VC++ Strings are not reference counted?

STL standard do not require from std::string to be refcounted. But in fact most of C++ implementations provide refcounted, copy-on-write strings, allowing you passing string by value as a primitive type. Also these implementations (at least g++)…
Artyom
  • 31,019
  • 21
  • 127
  • 215
14
votes
1 answer

What is implicit sharing?

I am building a game engine library in C++. A little while back I was using Qt to build an application and was rather fascinated with its use of Implicit Sharing. I am wondering if anybody could explain this technique in greater detail or could…
Dave
  • 7,283
  • 12
  • 55
  • 101
13
votes
1 answer

R: selecting subset without copying

Is there a way to select a subset from objects (data frames, matrices, vectors) without making a copy of selected data? I work with quite large data sets, but never change them. However often for convenience I select subsets of the data to operate…
ffriend
  • 27,562
  • 13
  • 91
  • 132
1
2 3
14 15