Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is implicit sharing?

I am building a game engine library in C++. A little while back I was using Qt to build an application and was rather fascinated with its use of Implicit Sharing. I am wondering if anybody could explain this technique in greater detail or could offer a simple example of this in action.

like image 469
Dave Avatar asked Jan 09 '11 06:01

Dave


People also ask

What is explicit sharing in Salesforce?

Salesforce uses explicit grants when records are shared directly to users or groups. Specifically, Salesforce uses explicit grants when: A user or a queue becomes the owner of a record. A sharing rule shares the record to a personal or public group, a queue, a role, or a territory.

How do I remove implicit sharing in Salesforce?

Implicit sharing is automatic. You can neither turn it off, nor turn it on. It is native to the Salesforce Platform. In other words, this isn't a configurable setting available in Salesforce.

What is Implicitparent in Salesforce?

In addition to sharing setting defined by system admin, there are a number of sharing behaviors that are built into Salesforce platform. This sharing is called implicit sharing, because it is not configured by administrators; it is defined and maintained by the system.


1 Answers

The key idea behind implicit sharing seems to go around using the more common term copy-on-write. The idea behind copy-on-write is to have each object serve as a wrapper around a pointer to the actual implementation. Each implementation object keeps track of the number of pointers into it. Whenever an operation is performed on the wrapper object, it's just forwarded to the implementation object, which does the actual work.

The advantage of this approach is that copying and destruction of these objects are cheap. To make a copy of the object, we just make a new instance of a wrapper, set its pointer to point at the implementation object, and then increment the count of the number of pointers to the object (this is sometimes called the reference count, by the way). Destruction is similar - we drop the reference count by one, then see if anyone else is pointing at the implementation. If not, we free its resources. Otherwise, we do nothing and just assume someone else will do the cleanup later.

The challenge in this approach is that it means that multiple different objects will all be pointing at the same implementation. This means that if someone ends up making a change to the implementation, every object referencing that implementation will see the changes - a very serious problem. To fix this, every time an operation is performed that might potentially change the implementation, the operation checks to see if any other objects also reference the implementation by seeing if the reference count is identically 1. If no other objects reference the object, then the operation can just go ahead - there's no possibility of the changes propagating. If there is at least one other object referencing the data, then the wrapper first makes a deep-copy of the implementation for itself and changes its pointer to point to the new object. Now we know there can't be any sharing, and the changes can be made without a hassle.

If you'd like to see some examples of this in action, take a look at lecture examples 15.0 and 16.0 from Stanford's introductory C++ programming course. It shows how to design an object to hold a list of words using this technique.

Hope this helps!

like image 155
templatetypedef Avatar answered Oct 08 '22 18:10

templatetypedef