Flat copy

from Wikipedia, the free encyclopedia

In object-oriented programming, the terms shallow copy and deep copy describe the way in which an object is duplicated.

Flat copy

Instead of a copy, an object only contains references to the structures or subordinate objects that are located at other addresses in the memory - therefore objects are also referred to as reference types (e.g. in language elements of C # ).

With a shallow copy, only the object is duplicated. The complex structures contained or references to subordinate objects are not duplicated. This means that there is another object (of the same type as the first object) in memory, the content of which contains references to the same structures and subordinate objects as in the original object. The content of the referenced objects and structures was therefore not duplicated.

Deep copy

A deep copy also creates a copy of all attributes of the object, so that the original object and its copy do not share any attributes. This can e.g. B. be carried out with the help of a copy constructor . Recursive attributes are left out.

Web links