next up previous contents index
Next: Expressions Up: ValuesTypes, and Constants Previous: Constant Values

Copy On Write

      This section really describes an implementational detail whose entire purpose is to prevent the user from having to worry about references or copying large values. Glish values are implimented using copy-on-write techniques. What this means for the user is that values are not copied until absolutly necessary. In the case of something like:

    a := 1:1e7
    b := a
a and b will, internal to Glish, share the same underlying storage. They will share the same storage until one of these values is modified so that semantically they can no longer share the storage. So if something like:
    a[1] := 90
was done, it would mean that a copy would have to be made. However, sometimes a copy may never have to be made. With the return value of a function for instance, a copy need not be made because the function never modifies the return value after it returns. In passing parameters, if the function does not modify one of the val parameters a copy is not made.

So while the user should not have to worry about the implimentation of the underlying values in Glish, understanding that copy-on-write is used to store values will explain the delayed copying cost and may provide some peace of mind.    

Thu Nov 13 16:44:05 EST 1997