When should I pass or return a struct by value?

On small embedded architectures (8/16-bitters) — always pass by pointer, as non-trivial structures don’t fit into such tiny registers, and those machines are generally register-starved as well. On PC-like architectures (32 and 64 bit processors) — passing a structure by value is OK provided sizeof(mystruct_t) <= 2*sizeof(mystruct_t*) and the function does not have many (usually … Read more

Shallow copy and deep copy in C

No. A shallow copy in this particular context means that you copy “references” (pointers, whatever) to objects, and the backing store of these references or pointers is identical, it’s the very same object at the same memory location. A deep copy, in contrast, means that you copy an entire object (struct). If it has members … Read more

Shallow copy or Deep copy?

From the link here 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 … Read more

Does Object.assign() create a deep copy or a shallow copy?

Forget about deep copy, even shallow copy isn’t safe, if the object you’re copying has a property with enumerable attribute set to false. MDN : The Object.assign() method only copies enumerable and own properties from a source object to a target object take this example var o = {}; Object.defineProperty(o,’x’,{enumerable: false,value : 15}); var ob={}; … Read more

JS: Does Object.assign() create deep copy or shallow copy

Forget about deep copy, even shallow copy isn’t safe, if the object you’re copying has a property with enumerable attribute set to false. MDN : The Object.assign() method only copies enumerable and own properties from a source object to a target object take this example var o = {}; Object.defineProperty(o,’x’,{enumerable: false,value : 15}); var ob={}; … Read more