Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marshal by bleed/reference/value?

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.

like image 873
GurdeepS Avatar asked Sep 03 '10 23:09

GurdeepS


People also ask

What is marshal by reference?

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.

What is 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.


1 Answers

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

Marshal By Reference

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.

Marshal By Value

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.

Marshal By Bleed

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

  • http://joeduffyblog.com/2006/08/21/dont-lock-on-marshalbybleed-objects/
like image 155
JaredPar Avatar answered Oct 17 '22 00:10

JaredPar