D
Dennis Myrén
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.
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.