Re: Passing arrays arguments using remoting versus calling directly

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Arkej (NOSPAMrobert.krt_at_REPLACESINETsiol.si)
Date: 02/11/05


Date: Fri, 11 Feb 2005 10:57:05 +0100

Hello.
This works with method params. How can I make the same for a property?

Robert

"Ken Kolda" <ken.kolda@elliemae-nospamplease.com> wrote in message
news:OzxMBPjAFHA.3264@TK2MSFTNGP12.phx.gbl...
> Because arrays are serializable, when you pass them across the remoting
> boundary the recipient gets a copy of the array (unlike when you call the
> method directly, in which case it's passed by reference). As an
> optimization, .NET remoting will not copy the array's elements back to the
> caller since this would mean copying the data twice and would be a
complete
> waste if the callee wasn't actually going to change any of the data in the
> array (i.e. it's purely an input parameter). This same rule actually
applies
> to all Serializable objects.
>
> However, in the cases when you DO want the serializable object passed back
> to the caller so they can see the changes made, you just need to modify
the
> function definition as follows:
>
> public Foo([In, Out] Byte[] someArray)
>
> The [In, Out] attributes tell .NET to marshal that parameter back to the
> caller when the function completes. (These attributes are defined in the
> System.Runtime.InteropServices). Just make sure you understand the
> performance implications before you do this -- if the array is large or
the
> number of changes being made by the callee are sparse, there's probably a
> better method than marshalling the entire array back to the caller.
>
> Ken
>
>
> "Ralph Flaugher" <RalphFlaugher@discussions.microsoft.com> wrote in
message
> news:DA4A6503-0473-4B56-A8A2-661D08A2EAE5@microsoft.com...
> > Can someone verify this for me?
> >
> > A function like: public Foo(Byte [] someArray) { someArray[0] = 1; }
> >
> > If Foo is called directly from within the assembly the caller's passed
> aray
> > will be affected by the call. However, if the object is exposed via
.Net
> > remoting and Foo is then called remotely, the caller's passed array will
> not
> > be affected unless Foo is changed to: public Foo(ref Byte [] someArray)
{
> > someArray[0] = 1; }
> >
> > In other words, an additional level of referencing/dereferencing is
> required
> > when using remoting. If this is true, is it also true for other
reference
> > types?
> >
> > --
> > Ralph Flaugher
>
>



Relevant Pages

  • Re: Passing arrays arguments using remoting versus calling directly
    ... When the MetersData array is ... >> themselves back to the server. ... >> are meant to be used over a remoting boundary. ... Writing good interfaces for ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Passing arrays arguments using remoting versus calling directly
    ... When the MetersData array is ... > are meant to be used over a remoting boundary. ... > array cause the entire MetersData object to be serialized to the client, ... you should be writing very clear method interfaces such as: ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Passing arrays arguments using remoting versus calling directly
    ... when you pass them across the remoting ... caller since this would mean copying the data twice and would be a complete ... array. ... to all Serializable objects. ...
    (microsoft.public.dotnet.framework.remoting)
  • RE: Array marshaling
    ... "Gleb Holodov" wrote: ... A server might change contents of an array, so remoting has no ... > won't be sent back to a client when remoting methods like these, ...
    (microsoft.public.dotnet.framework.remoting)
  • Array marshaling
    ... A server might change contents of an array, so remoting has no ... won't be sent back to a client when remoting methods like these, ... void Method(SomeClassar); ...
    (microsoft.public.dotnet.framework.remoting)