COW cloning

Suman Ganta
suman_ganta
Published in
1 min readMay 3, 2007

Deep cloning an object is not always needed to replicate objects. Doing deep cloning may give dreaded performance results based on the type of object (best example, yes you rightly guessed it, Hashmap). Hashmap’s clone() method does the shallow copy of the map keeping the object references same in both the maps. This doesn’t help in most of the cloning needs.

Another way of implementing the cloning is copy-on-write (COW) cloning. In this way, deep cloning of a particular reference will only happen when it gets updated. This type of on-demand cloning cannot be implemented in a generic fasion (any disagrees here?) However it can be implemented on data structure category basis — Maps, Sets etc.,

I’m putting together few such cloners and will post them soon here.

--

--