Re: Passing an object reference 1000 times
From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 11/12/04
- Next message: Dennis Myrén: "Re: Passing an object reference 1000 times"
- Previous message: Dennis Myrén: "Re: Passing an object reference 1000 times"
- In reply to: Dennis Myrén: "Re: Passing an object reference 1000 times"
- Next in thread: Dennis Myrén: "Re: Passing an object reference 1000 times"
- Reply: Dennis Myrén: "Re: Passing an object reference 1000 times"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 12 Nov 2004 09:30:32 -0500
Dennis,
Like I said before, I don't think that this is the issue. I think that
if you ran some performance tests between the two, you wouldn't find any
difference.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"Dennis Myrén" <dennis@oslokb.no> wrote in message
news:sJ3ld.16330$Km6.175390@news4.e.nsc.no...
> Thank you for answering, Nicholas.
>
> Actually, i do know i am passing a *reference* to the object; a 32-bit
> integer.
> However, it still a lot of 32-bit integers.
> So, you think i should go for passing by value rather than by
> reference(ref)?
>
> --
> Regards,
> Dennis JD Myrén
> Oslo Kodebureau
> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote
> in message news:Oy$mfKMyEHA.3376@TK2MSFTNGP12.phx.gbl...
>> Dennis,
>>
>> I think that the assumption you are making is that when you are
>> passing a reference type around, you are copying it as you make the call
>> passing the object. This is not the case. You are passing a reference,
>> which is very small compared to the actual object size.
>>
>> If you are feeling slowdown, then it is most likely because of code IN
>> the method, and not how you are passing the parameters. If you were to
>> take some performance numbers between passing it with and without the ref
>> keyword, I think you would find they are pretty much exactly the same.
>>
>> Hope this helps.
>>
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - mvp@spam.guard.caspershouse.com
>>
>> "Dennis Myrén" <dennis@oslokb.no> wrote in message
>> news:ik3ld.16323$Km6.175314@news4.e.nsc.no...
>>>I have these tiny classes, implementing an interface through which their
>>>method
>>> Render ( CosWriter writer ) ;
>>> is called.
>>> Given a specific context, there are potentially a lot of such objects,
>>> each requiring a call to that method to fulfill their purpose.
>>> There could be 200, there could be more than 1000.
>>> That is a lot of references passed around. It feels heavy.
>>>
>>> Let us say i changed the signature of the interface method to:
>>> Render ( ref CosWriter writer ) ;
>>> to pass an existing reference to a CosWriter instance(CosWriter is a
>>> class).
>>>
>>> Because the ref keyword is thought to be used to actually change that
>>> parameter in the method to which it was passed,
>>> would it be considered bad practice, passing an instance by reference,
>>> although i will not change that parameter in the method?
>>>
>>> I am not very keen on passing this instance by value that much, when i
>>> can use the same reference.
>>> I would earn a lot in both memory allocation and speed, would i not?
>>>
>>> The only option i have to the Render method implementation on each of
>>> this objects,
>>> is i could check what type each one is, cast to that type to be able to
>>> access a specific property
>>> of it, and perform what otherwise that method Render does, suppressing
>>> that method.
>>> Could that be more efficient? I doubt.
>>>
>>> Those properties is mostly System.Int32, in some cases they are
>>> reference types.
>>> So i would not earn anything from that, would i?
>>>
>>>
>>> Please give me some guidelines, and i am very grateful.
>>>
>>>
>>>
>>> --
>>> Regards,
>>> Dennis JD Myrén
>>> Oslo Kodebureau
>>>
>>
>>
>
>
- Next message: Dennis Myrén: "Re: Passing an object reference 1000 times"
- Previous message: Dennis Myrén: "Re: Passing an object reference 1000 times"
- In reply to: Dennis Myrén: "Re: Passing an object reference 1000 times"
- Next in thread: Dennis Myrén: "Re: Passing an object reference 1000 times"
- Reply: Dennis Myrén: "Re: Passing an object reference 1000 times"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|