By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

Passing an object reference 1000 times

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:ik********************@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

Nov 16 '05 #2

P: n/a
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]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Oy**************@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]
- mv*@spam.guard.caspershouse.com

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:ik********************@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


Nov 16 '05 #3

P: n/a
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]
- mv*@spam.guard.caspershouse.com
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:sJ********************@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]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Oy**************@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]
- mv*@spam.guard.caspershouse.com

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:ik********************@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



Nov 16 '05 #4

P: n/a
OK, maybe i should stick with the current signature.
It is just that, i think, if i can avoid creating 1000 32-bit integers, and
still provide the same functionality, it feels like i should.

Thank you once again, Nicholas.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uO**************@TK2MSFTNGP12.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:sJ********************@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]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Oy**************@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]
- mv*@spam.guard.caspershouse.com

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:ik********************@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



Nov 16 '05 #5

P: n/a
Dennis,

Well, think of it like this, SOMETHING has to be passed, right?
Assuming a reference and a reference to a reference are passed the same way,
it doesn't matter what you are doing, because you are always going to pass
something. If the weight for passing something by ref was different than by
val for reference types, then I would say look into it, but it isn't =)
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:BT********************@news4.e.nsc.no...
OK, maybe i should stick with the current signature.
It is just that, i think, if i can avoid creating 1000 32-bit integers,
and still provide the same functionality, it feels like i should.

Thank you once again, Nicholas.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:uO**************@TK2MSFTNGP12.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:sJ********************@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]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Oy**************@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]
- mv*@spam.guard.caspershouse.com

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:ik********************@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
>



Nov 16 '05 #6

P: n/a
Thank you, Nicholas.

I think that you have now convienced me to stick with my current signature.

I am wishing you a happy weekend.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
Dennis,

Well, think of it like this, SOMETHING has to be passed, right?
Assuming a reference and a reference to a reference are passed the same
way, it doesn't matter what you are doing, because you are always going to
pass something. If the weight for passing something by ref was different
than by val for reference types, then I would say look into it, but it
isn't =)
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:BT********************@news4.e.nsc.no...
OK, maybe i should stick with the current signature.
It is just that, i think, if i can avoid creating 1000 32-bit integers,
and still provide the same functionality, it feels like i should.

Thank you once again, Nicholas.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:uO**************@TK2MSFTNGP12.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:sJ********************@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]" <mv*@spam.guard.caspershouse.com>
wrote in message news:Oy**************@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]
> - mv*@spam.guard.caspershouse.com
>
> "Dennis Myrén" <de****@oslokb.no> wrote in message
> news:ik********************@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
>>
>
>



Nov 16 '05 #7

P: n/a
just think of it this way, if copying a 32 bit integer is truely a issue,
then microsoft would have implemented the whole thing very differently.
every time you call something in the BCL, you have to pass things around. we
better keep our fingers crossed that it's not a bottleneck. :)

"Dennis Myrén" wrote:
OK, maybe i should stick with the current signature.
It is just that, i think, if i can avoid creating 1000 32-bit integers, and
still provide the same functionality, it feels like i should.

Thank you once again, Nicholas.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uO**************@TK2MSFTNGP12.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:sJ********************@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]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Oy**************@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]
- mv*@spam.guard.caspershouse.com

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:ik********************@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
>



Nov 16 '05 #8

P: n/a
I now created a benchmark on the two approaches,
and i actually see the approach using instance passed by reference twice as
fast.

But both approaches is still extremely fast, so there is no significant
difference.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:BT********************@news4.e.nsc.no...
OK, maybe i should stick with the current signature.
It is just that, i think, if i can avoid creating 1000 32-bit integers,
and still provide the same functionality, it feels like i should.

Thank you once again, Nicholas.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:uO**************@TK2MSFTNGP12.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:sJ********************@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]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Oy**************@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]
- mv*@spam.guard.caspershouse.com

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:ik********************@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
>



Nov 16 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.