How do objects get sent over a network transfer without invalidating header information
Does a an object have any header data that is relative to its current machine and process, and if so, how does this object transfer over a network connection without invalidating this kind of data? I know I can't directly copy the binary data of an object across a network connection to another pc/process, and the other process on the other machine just interpret (cast) the binary data as an object.
Are there any ways t开发者_如何学Co calculate how much data cut out of a binary block of data (parsed into an object) would justify using a serialized object over just passing the binary data.
A .net object can be transmitted across process boundaries in only 2 ways: Serialization and MarshalByRef.
Serialization
This simply takes the values of (most) fields on the object and stores them in a SerializationInfo instance. Then, your formatter of choice converts that into bytes on a Stream. This has no "header information" like you mention... it usually has the Type name and Assembly FullName in which the Type is defined.
MarshalByRefObject
This is a .NET remoting base class which means that method calls from other appdomains may be marshaled across AppDomain boundaries to this one, making it seem to users of your object that they have a reference to your object. In this case the foreign AppDomain merely holds a proxy to your object. This proxy holds the relevant information.
A general C# object is attached to its machine and process by virtue of being managed by the .net framework (so under the control of the garbage collector and so on).
But when you serialise and de serialise your object you wouldn't make any reference to such information.
It's up to you how you serialize and reconstruct objects at the other end. It's language agnostic.
Normally when transfering C# (or .NET object) all that gets transferred is the (user)state not internal .NET state. There might be internal object state of which we as ordinary programmers don't know but that is up to the developers of the .NET Runtime.
So when an object is transferred/serialized this kind of information (pointers etc.) are ignored or transformed into runtime independed identified or numbers.
精彩评论