[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


In python, this is the difference between:

  a = b[:]  # copy the entire array b into a


  a = b     # a now refers to the same array as b

Seems pretty straightforward, unless I'm missing something deeper.
Even java has Clone() methods.


> Date: Mon, 10 Dec 2001 14:35:54 -0800 (PST)
> From: Morgan McGuire <morgan3d@yahoo.com>
> > Copy-on-mutate?  What's that?
> Copy-on-mutate is a form of lazy evaluation.  It means that:
> A = B
> doesn't actually copy the values from B into A (A and B are values, not
> pointers), instead it just remembers that A is supposed to be equal to
> B.  This saves memory and time.  If we later mutate A or B, the copy
> occurs.  If you're extra slick, you can put off the copy until a
> significant mutation occurs (just accumulate the mutations to apply
> later) or until someone actually needs the value.
> When big data structures are involved, this is a very handy
> optimization, expecially if parts of data structures get lazily copied.
>  It also means you never use pointers for efficiency, only for
> semantics.
> -m