Friday 24 November 2017

language agnostic - What is the difference between a deep copy and a shallow copy?





What is the difference between a deep copy and a shallow
copy?



Answer




Shallow copies duplicate as little as
possible. A shallow copy of a collection is a copy of the collection structure, not the
elements. With a shallow copy, two collections now share the individual
elements.



Deep copies duplicate everything. A
deep copy of a collection is two collections with all of the elements in the original
collection duplicated.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...