remoting general marshal

T

Tom

I think I'm still a little rough on the principle and understanding of
Marshal by value and Marshal by reference after reading various materials.

my understanding of Marshal by value is that the object is copied and passed
by value out of the application domain. So does that mean the ENTIRE server
object is copied to the client side ? thus all calculations are done on the
client side ?

ie. if client/server

if server has add(int x, int y)

and client calls on server add(5,6)

by Marshal by value does that mean the ENTIRE object of add is copied and
process of 5 + 6 is performed on the client ? is that what it means ?

but then again my understanding of an OBJECT is simply a reference to a
class or method. so copying an object is merely copying a method's reference
so what is the difference between Marshal by value and Marshal by reference
?


Thanks guys, I have read many books but still can't grasp it.

Tom
 
N

Nicholas Paldino [.NET/C# MVP]

Tom,

See inline:
my understanding of Marshal by value is that the object is copied and
passed
by value out of the application domain. So does that mean the ENTIRE
server
object is copied to the client side ? thus all calculations are done on
the
client side ?

ie. if client/server

if server has add(int x, int y)

and client calls on server add(5,6)

by Marshal by value does that mean the ENTIRE object of add is copied and
process of 5 + 6 is performed on the client ? is that what it means ?

The concept of whether or not something is passed by reference or by
value (as it relates to remoting) applies to a type when it is used as a
parameter to a call that occurs outside of the current app domain. In this
case, you determine whether or not 5 and 6 are passed by value or by
reference to the other app domain. Because they are of type Int32, and that
does not derive from MarshalByRefObject, it will be passed by value. This
means that the values of 5 and 6 will be copied over to the new application
domain, and any changes made to them are not going to be seen by you.

Now, if the signature looked like this:

DoSomething(System.Windows.Forms.Control control)

And you passed a textbox, then the TextBox would not be copied. Rather,
a reference to it would be passed to the new application domain. Any calls
made to the control parameter in the other application domain would be
remoted back to the connecting client.

Hope this helps.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Tom,
my understanding of Marshal by value is that the object is copied and
passed
by value out of the application domain.

Copy and paste implies that the clipboard is involved. The clipboard is not
involved the object is serialized (its data part of course) whether in a
binary stream or in some text format (SOAP) send thru some channel to the
client and deserialized on the cliend side in the client's environment. From
this point on the obejct lives and works on the client machine.
So does that mean the ENTIRE server
object is copied to the client side ? thus all calculations are done on
the
client side ?

Entire server or whatever object is used. It is possible that the server is
not one monolithic object. it might use couple of helper objects that can be
serialized by value and perform some operation on the client side. The core
of the server on the other side might be (and usually is) marchaled by ref
and lives on the server machine.
if server has add(int x, int y)

and client calls on server add(5,6)

by Marshal by value does that mean the ENTIRE object of add is copied and
process of 5 + 6 is performed on the client ? is that what it means ?

No, the process of marchaling (serialization/deserialization) of the object
that declares this method is done when you request that object rather than
when you call its methods. I'd say 'request the object' because if you
careate the object with *new* operator it is not different than creation of
any other local object. Marshaling occures when you get that object as
return value or form property of the marshaled by ref object on the server.
See marchaled by value means that the object has nothing special beside that
it is serializable.

but then again my understanding of an OBJECT is simply a reference to a
class or method. so copying an object is merely copying a method's
reference
so what is the difference between Marshal by value and Marshal by
reference
?

Marshal by ref means that one the server and cliend sides proxy objects are
created. Those proxies are in charge of treansfer the method calls between
them via some medium and hide the fact form the client that actually the
real logic and data are on other machine(or process or whatever). What the
client actually works with is a proxy object. That's why when you marchal by
ref only methods can be called (or properties, which are methods after all).
Marchal by value on the other hand means that state of the object (data ) is
packed and send to the client. Then the client creates a new object and
initilizes it with that data. So it gets copy of the object on its side.
This is totally new object and has nothing to do with its original on the
server.

This is most likely ref and value objects when remoting is not involved. You
know that when you copy reference to a ref object only the reference is copy
(the address so to speak). The object in the heap is only one. When you
copy value objects (like Int32 for example) you get new copy and from this
point on both objects has nothing to do with each other and they live
separate lives.
 
T

Tom

ahh thankyou now I understand


Nicholas Paldino said:
Tom,

See inline:
my understanding of Marshal by value is that the object is copied and
passed
by value out of the application domain. So does that mean the ENTIRE
server
object is copied to the client side ? thus all calculations are done on
the
client side ?

ie. if client/server

if server has add(int x, int y)

and client calls on server add(5,6)

by Marshal by value does that mean the ENTIRE object of add is copied and
process of 5 + 6 is performed on the client ? is that what it means ?

The concept of whether or not something is passed by reference or by
value (as it relates to remoting) applies to a type when it is used as a
parameter to a call that occurs outside of the current app domain. In this
case, you determine whether or not 5 and 6 are passed by value or by
reference to the other app domain. Because they are of type Int32, and that
does not derive from MarshalByRefObject, it will be passed by value. This
means that the values of 5 and 6 will be copied over to the new application
domain, and any changes made to them are not going to be seen by you.

Now, if the signature looked like this:

DoSomething(System.Windows.Forms.Control control)

And you passed a textbox, then the TextBox would not be copied. Rather,
a reference to it would be passed to the new application domain. Any calls
made to the control parameter in the other application domain would be
remoted back to the connecting client.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

but then again my understanding of an OBJECT is simply a reference to a
class or method. so copying an object is merely copying a method's
reference
so what is the difference between Marshal by value and Marshal by
reference
?


Thanks guys, I have read many books but still can't grasp it.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top