views:

57

answers:

3

Last week a young student ask me if marshalling is the same as casting. My answer was definetly no. Marshalling is seralization, the way to transform a memory representation of an objet into bytes in order to be transmitted to a network whereas casting is related to type convertion / coercion.

Later on, rethinking the question I was thought that marshalling can be seen as a special case of casting. For example the transformation of the memory representation is in xml then one can say that you are "casting" to the type defined by the corresponding xsd grammar of that xml file.

What do you think about this?

A: 

Marshalling is generally about a technology boundary (e.g. going across a network or from one memory type to another as in the case of managed/unmanaged) whereas casting is generally within the same technology boundary therefore I think they are definitely different things.

It would be exceptionally confusing if we used the same term for both approaches meaning we would need to define them differently as they have different behaviours.

Tollo
+2  A: 

Casting doesn't modify the data type. That is a major distinction. When you marshal something, you are transforming the data into something else.

A simple cast only changes how you are interpreting the object, not what the object is internally.

I agree that the distinction should be clear else unfamiliar people may be confused.

Kekoa
A: 

They're both a "type conversion", but, they are different kinds of type conversion: casting is usually between related object types (e.g. a downcast from a superclass to a subclass), whereas a marshalling might be for example from an object graph to plain-text representation.

ChrisW