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

Static Method Parameters issue

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.