Re: performance hit using byref or byval?
From: Max (nospam_at_notvalid.com)
Date: 10/26/04
- Next message: Louise: "Re: Where is MAKEWPARAM"
- Previous message: carlor: "Creating similar versions of apps with inheritance"
- In reply to: Tom Dacon: "Re: performance hit using byref or byval?"
- Next in thread: Herfried K. Wagner [MVP]: "Re: performance hit using byref or byval?"
- Reply: Herfried K. Wagner [MVP]: "Re: performance hit using byref or byval?"
- Reply: Tom Dacon: "Re: performance hit using byref or byval?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 26 Oct 2004 15:41:58 -0400
Ok that puts my mind at ease. I guess what I was reading is that byref
causes more roundtrips in terms of speed rather than the memory usage a
byval might cause. Byval might be faster if I don't mind the memory
overhead. I suppose the issue is insignificant as long as I'm not byrefing a
datagrid a million times in a huge loop or something and expecting fast
results.
-Max
"Tom Dacon" <tdacon@community.nospam> wrote in message
news:OZ9rQ33uEHA.3840@TK2MSFTNGP12.phx.gbl...
> You're not actually passing the huge object around when you use byref. All
> you're passing is the reference to the object, which resides on the heap.
> This is a bit subtle, but this is how it works:
>
> When you pass a reference to an object by value, the receiving method
> receives a copy of the reference, guaranteeing that when the method
> returns to the calling code that the reference will be unchanged (i.e.,
> will not point to a different object on the heap).
>
> When you pass a reference to an object by reference, the receiving method
> is in essence operating directly on the caller's variable, and could in
> principle change it so that it points to some new object of the same type.
>
> In either case, the cost of passing the object reference is very slight,
> so you should make your choice about passing convention on other
> considerations, such as whether you want to protect the variable's value
> from the called method, or whether the called method is authorized to
> change it.
>
> These rules apply to objects created on the heap. Objects created on the
> stack (structs/Types), I believe, have other considerations.
>
> HTH,
> Tom Dacon
> Dacon Software Consulting
>
> "Max" <nospam@notvalid.com> wrote in message
> news:eLElvj3uEHA.3624@TK2MSFTNGP09.phx.gbl...
>> New to winforms, I'm trying to break up my code to not have so much in
>> the main form, so I'm moving code outside into reusable code. My concern
>> is that I'm passing huge objects like entire datagrids BYREF to modify
>> and molest in my functions. Are there any performance issues I need to
>> worry about? I want my app to use as little memory and cpu resources as
>> possible.
>>
>> -Max
>>
>
>
- Next message: Louise: "Re: Where is MAKEWPARAM"
- Previous message: carlor: "Creating similar versions of apps with inheritance"
- In reply to: Tom Dacon: "Re: performance hit using byref or byval?"
- Next in thread: Herfried K. Wagner [MVP]: "Re: performance hit using byref or byval?"
- Reply: Herfried K. Wagner [MVP]: "Re: performance hit using byref or byval?"
- Reply: Tom Dacon: "Re: performance hit using byref or byval?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|