Re: Passing arrays arguments using remoting versus calling directly
From: Arkej (NOSPAMrobert.krt_at_REPLACESINETsiol.si)
Date: 02/11/05
- Next message: Daniel Moth: "Re: How to ensure that port is unused?"
- Previous message: Jako Menkveld: "Re: Killing a thread started with delegate.BeginInvoke()"
- Next in thread: Ken Kolda: "Re: Passing arrays arguments using remoting versus calling directly"
- Reply: Ken Kolda: "Re: Passing arrays arguments using remoting versus calling directly"
- Messages sorted by: [ date ] [ thread ]
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
>
>
- Next message: Daniel Moth: "Re: How to ensure that port is unused?"
- Previous message: Jako Menkveld: "Re: Killing a thread started with delegate.BeginInvoke()"
- Next in thread: Ken Kolda: "Re: Passing arrays arguments using remoting versus calling directly"
- Reply: Ken Kolda: "Re: Passing arrays arguments using remoting versus calling directly"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|