

Matlab’s internal memory representation (2012) - PascLeRasc
http://undocumentedmatlab.com/blog/matlabs-internal-memory-representation

======
chrisBob
I recently learned about copy on write the hard way: We had a buggy dll from a
hardware vendor that was editing our input, so the obvious solution was to
keep a copy of the data we sent it. To our surprise, even the copy we made
changed unless we did it in an assignment like A = 1.0*X;

On a related note the tech support at MATLAB is very responsive. Every time I
have had an issue they get back to me quickly, and I feel like the follow up
and really fix bugs.

~~~
dr_zoidberg
This reminds me of the "copy list" expression in Python:

    
    
        In [1]: a = [1, 2, 3]
        In [2]: b = a
        In [3]: a is b
        Out[3]: True
        In [4]: b = a[:]
        In [5]: a is b
        Out[5]: False
    

Usually this kind of "optimization" is done to avoid copying large ammounts of
data in memory, but as you said, unless it's widesepread knowledge or
explicitly stated, it can lead to some confusing situations/bugs.

~~~
animefan
In almost all cases knowledge of copy-on-write doesn't have to be widespread
because it is equivalent to value semantics.

It is only because they were using a buggy dll (which for non-matlab users, is
custom native code that matlab calls against using a FFI), that the expected
semantics of matlab were violated.

