471,338 Members | 1,275 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

Static Method Parameters issue

Hi,

Mine is a very basic doubt ...

(1) If we are using a static field/object, then the field/object is shared
across all the places in the entire application as it is stored only at one
place.
(2) If it is an instance-based object, then when each instance gets created,
a new memory space gets allocated to every instance.

Now coming to methods,
(3) In the case of instance-based methods, there will be only copy of the
method existing in the memory (yes only one irrespective of the number of
instances using it). This is so because, there will be an instance
intrinsically passed to this instance-based method (we need not specify
this). This implicitly passed parameter is 'this' in C# and 'Me' in VB .NET
which refers to the instance calling that method. The method then operates on
this instance passed.
(4) The case is same in the case of static methods also except that the
implicit 'this' or 'Me' wont be passed. Now for my question: In this static
method, how are the parameters stored ... specifically when multiple objects
calls this instance-based method passing different parameters, then is there
any risk of corruption or how does this work??

Kindly correct me if I'm wrong anywhere...

Thanks in advance.
--
Samba!

Aug 2 '05 #1
2 1889
check out this link which clearly explains how parameters are stored and
evaluated for static functions..Hope this will give u an better idea...
http://msdn.microsoft.com/library/de...spec_7_4_1.asp

"Samba" wrote:
Hi,

Mine is a very basic doubt ...

(1) If we are using a static field/object, then the field/object is shared
across all the places in the entire application as it is stored only at one
place.
(2) If it is an instance-based object, then when each instance gets created,
a new memory space gets allocated to every instance.

Now coming to methods,
(3) In the case of instance-based methods, there will be only copy of the
method existing in the memory (yes only one irrespective of the number of
instances using it). This is so because, there will be an instance
intrinsically passed to this instance-based method (we need not specify
this). This implicitly passed parameter is 'this' in C# and 'Me' in VB .NET
which refers to the instance calling that method. The method then operates on
this instance passed.
(4) The case is same in the case of static methods also except that the
implicit 'this' or 'Me' wont be passed. Now for my question: In this static
method, how are the parameters stored ... specifically when multiple objects
calls this instance-based method passing different parameters, then is there
any risk of corruption or how does this work??

Kindly correct me if I'm wrong anywhere...

Thanks in advance.
--
Samba!

Aug 2 '05 #2
Samba <sr****@dotnet.microsoft.com> wrote:
Mine is a very basic doubt ...

(1) If we are using a static field/object, then the field/object is shared
across all the places in the entire application as it is stored only at one
place.
(2) If it is an instance-based object, then when each instance gets created,
a new memory space gets allocated to every instance.

Now coming to methods,
(3) In the case of instance-based methods, there will be only copy of the
method existing in the memory (yes only one irrespective of the number of
instances using it). This is so because, there will be an instance
intrinsically passed to this instance-based method (we need not specify
this). This implicitly passed parameter is 'this' in C# and 'Me' in VB .NET
which refers to the instance calling that method. The method then operates on
this instance passed.
What do you mean by "copy of the method"? You need to be *very* clear
as to what you mean by that - I suspect that when you try to explain
it, you'll find the problem goes away.
(4) The case is same in the case of static methods also except that the
implicit 'this' or 'Me' wont be passed. Now for my question: In this static
method, how are the parameters stored ... specifically when multiple objects
calls this instance-based method passing different parameters, then is there
any risk of corruption or how does this work??


Parameters are stored on the stack, whether for instance methods or
static methods. They don't interfere with each other (although if those
parameters are references to other objects, then things become a bit
more complicated, of course).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Aug 2 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by superseed | last post: by
2 posts views Thread by Samba | last post: by
12 posts views Thread by chandu | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.