I have heard about marshal by reference, marshal by bleed and marshal by value. What exactly are the differences between these 3? I know that these are used when transporting data across appdomains/serialization but not much more.
MarshalByRefObject is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit from MarshalByRefObject are implicitly marshal by value.
One specialized use of custom marshaling is known as marshal-by-value. When interface pointers are unmarshaled in COM+, the client always receives a pointer, usually through a proxy, to the original object; this is known as marshal-by-reference because the client receives a reference to the object.
The different forms of marshaling are used to describe how objects behave when they are passed between AppDomain instances via normal function calls. An AppDomain is often known as a light weight process and provides an isolated container for managed objects to run in. Here's a quick breakdown of the different types
All types which derive from MarshalByRefObject will marshal by reference. These object instances do not travel between AppDomain instances. They are allocated in a specific AppDomain and do not leave it.
When a reference to a MarshalByRefObject is passed across an AppDomain boundary a proxy is created in the target AppDomain. This proxy can be used to manipulate the object in the original AppDomain but the object itself is not directly accessible.
Essentially the opposite of MarshalByRefObject. When these values are passed across AppDomain boundaries they are serialized via binary serialization and deserialized in the target AppDomain instance. The result is two, hopefully, independent values. One in each domain.
Certain classes of types are known as Domain Neutral. In particular string, Type and other reflection members. These objects do not live in a particular AppDomain and references to them can be freely shared between them. They are similar to marshal by reference in that duplicates are not created but proxies are not created either. Instead the direct reference is shared between AppDomain instances.
You should take a look at Joe Duffy's blog entry on the subject
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With