Sharing between dynamic data objects

During the assignment of reference variables, only the references are copied. After an assignment, source and target variable point to exactly the same data object and the same instance of a class respectively. (to the header).

During assignments between strings and internal tables, a so called sharing occurs. That means, the actual data values are not copied for the time being. Merely the necessary administration entries are copied, so that the target object refers to the same data as the source object.

With strings, a new internal reference is created that points to the already existing string header. With internal tables, a new internal reference and a new table header are created, which refers to the existing table body.

The sharing is canceled exactly when there occurs a changing access to either the source or target object (Copy-on-write semantics). Then, the actual copying process for the data values occurs and the references and headers respectively are changed accordingly.

The following figure illustrates the sharing of dynamic data objects. The upper part shows on the left hand side the principle of sharing for strings and on the right hand side the sharing for internal tables. The lower part depicts how the sharing is terminated when a change is carried out on the source or target object.

Note