copy-on-write

R: selecting subset without copying

允我心安 提交于 2019-12-29 04:02:31
问题 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 on. Making a copy of a large subset each time is very memory inefficient, but both normal indexing and subset (and thus xapply() family of functions) create copies of selected data. So I'm looking for functions or data structures that can overcome

Does Matlab ever copy data passed to a mex function?

被刻印的时光 ゝ 提交于 2019-12-23 04:57:29
问题 Concerning lazy copying: Will Matlab ever copy data passed to a mexFunction, which modifies it? For instance in myMex(input1(:,:,ii), input2(:,:,ii)) can one be sure, that the input matrices are never copied, so that one can pass something in and modify it, without having to return a reference? 回答1: In certain cases, MATLAB implements some optimizations to avoid copying data when calling functions. With MEX-functions, the input as passed as const mxArray *prhs[] ( prhs is an array of pointers

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

两盒软妹~` 提交于 2019-12-21 02:56:51
问题 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"

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

我们两清 提交于 2019-12-19 07:16:10
问题 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

Would mutating an ArraySlice instantiate a new array instance?

邮差的信 提交于 2019-12-18 08:24:51
问题 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 (

Would mutating an ArraySlice instantiate a new array instance?

大城市里の小女人 提交于 2019-12-18 08:23:34
问题 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 (

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

蓝咒 提交于 2019-12-18 04:11:02
问题 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? 回答1:

Why VC++ Strings are not reference counted?

末鹿安然 提交于 2019-12-18 03:32:17
问题 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

Why VC++ Strings are not reference counted?

戏子无情 提交于 2019-12-18 03:32:17
问题 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

In Java can I depend on reference assignment being atomic to implement copy on write?

混江龙づ霸主 提交于 2019-12-17 18:41:55
问题 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? Something like: private Collection global = new HashSet(); // start threading after this void allUpdatesGoThroughHere(Object exampleOperand) { // My hypothesis is that this prevents operations in the block being re-ordered synchronized(global) {