copy-on-write

How to know whether a copy-on-write page is an actual copy?

扶醉桌前 提交于 2019-11-29 14:33:59
问题 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 copied. There is a call, called 'mincore', but that only reports whether the page is in memory or not, which is not the same as the page being copied or not. Is there some way to figure out which pages have been copied ? 回答1: Good, following the

Would mutating an ArraySlice instantiate a new array instance?

懵懂的女人 提交于 2019-11-29 14:03:39
var absences = [0, 2, 0, 4, 0, 3, 1, 0] let midpoint = absences.count / 2 var firstHalf = absences.prefix(upTo: midpoint) let secondHalf = absences.suffix(from: midpoint) Quotation from Apple: Neither the firstHalf nor secondHalf slices allocate any new storage of their own. Instead, each presents a view onto the storage of the absences array. When I try to mutate firstHalf as the following: firstHalf[1] = 19 the values of firstHalf changes but the original array absences remains the same ( firstHalf[1] is equal to 19 while absences[1] equals to 2) So what happens in the background. Did I

In place modification of matrices in R [duplicate]

旧时模样 提交于 2019-11-29 13:13:52
This question already has an answer here: Operator “[<-” in RStudio and R 1 answer 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] "08429190" y[2:3,] <- matrix(c(1,1,8,12),nrow=2) address(y) [1] "0E033D28" Nick Kennedy I get the same behaviour as the OP using R 3.2.0 running within RStudio 0.99.441 on Windows 8.1 and using pryr::address . The issue is RStudio has a reference to y for its Environment

How can I make a container with copy-on-write semantics? (Swift)

為{幸葍}努か 提交于 2019-11-29 05:11:42
I have a very large structure, which I want to ensure is not copied needlessly. How can I make a copy-on-write container for it? A copy-on-write is usually a struct wrapper over some backing object. public final class MutableHeapStore<T>: NonObjectiveCBase { public typealias Storage = T public private(set) var storage: Storage public init(storage: Storage) { self.storage = storage } } public struct COW<T> { public typealias Storage = MutableHeapStore<T> public typealias Value = T public var storage: Storage public init(storage: Storage) { self.storage = storage } public var value: Value { get

Get the copy-on-write behaviour of fork()ing, without fork()

心不动则不痛 提交于 2019-11-29 04:22:45
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 allocated by the kernel, the rest would continue to be shared. I'd like to make a copy of buf, but I'm only going to change a little of the copy. I'd like copy-on-write behaviour without forking. (Like you get for free when forking.) Is this possible? You'll want to create a file on disk or a POSIX shared memory segment ( shm_open ) for the block. The first

remove elements from CopyOnWriteArrayList

一个人想着一个人 提交于 2019-11-29 02:42:45
问题 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 -

Why VC++ Strings are not reference counted?

人盡茶涼 提交于 2019-11-29 01:40:56
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++) use atomic operations making these string lock-free and thread safe. Easy test shows copy-on-write semantics: #include <iostream> #include <string> using namespace std; void foo(string s) { cout<<(void*)s.c_str()<<endl; string ss=s; cout<<(void*)ss.c_str()<<endl; char p=ss[0]; cout<<(void*)ss.c_str()<<endl; } int main() { string s="coocko"; cout<<(void

In place modification of matrices in R [duplicate]

末鹿安然 提交于 2019-11-28 07:06:29
问题 This question already has an answer here : Operator “[<-” in RStudio and R (1 answer) Closed 4 months ago . 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] "08429190" y[2:3,] <- matrix(c(1,1,8,12),nrow=2) address(y) [1] "0E033D28" 回答1: I get the same behaviour as the OP using R 3.2.0 running within

What is implicit sharing?

不打扰是莪最后的温柔 提交于 2019-11-28 06:02:20
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 offer a simple example of this in action. The key idea behind implicit sharing seems to go around using the more common term copy-on-write . The idea behind copy-on-write is to have each object serve as a wrapper around a pointer to the actual implementation. Each implementation object keeps track of the number of pointers into it. Whenever an

Which segments are affected by a copy-on-write?

大城市里の小女人 提交于 2019-11-28 01:38:10
问题 My understanding of copy-on-write is that "Everyone has a single, shared copy of the same data until it's written, and then a copy is made". Is a shared copy of the same data comprised of a heap and bss segment or only heap? Which memory segments will be shared, and is this dependent on the OS? 回答1: The OS can set whatever "copy on write" policy it wishes, but generally, they all do the same thing (i.e. what makes the most sense). Loosely, for a POSIX-like system (linux, BSD, OSX), there are