All,
When I create a class with a static member variable and reference that
class in a console applicaton it appears as though each instance of the
application has its own separate copy of the member variable.
Therefore, it would appear that the scope of a static class member is
limited to a specific instance of an application that happens to be
running on the machine.
Is this correct?
Thanks,
--Jonathan 10 2126
"ne************ @hotmail.com" <ne************ @hotmail.com> wrote: When I create a class with a static member variable and reference that class in a console applicaton it appears as though each instance of the application has its own separate copy of the member variable.
Therefore, it would appear that the scope of a static class member is limited to a specific instance of an application that happens to be running on the machine.
Is this correct?
Every application runs in its own address space with its own variables,
unless you work hard (via shared memory or some other technique) to make
it otherwise.
-- Barry
Hello, Barry!
BK> Every application runs in its own address space with its own variables,
BK> unless you work hard (via shared memory or some other technique) to
BK> make it otherwise.
Scope of static var can be limited to the scope of the thread via ThreadStaticAtt ribute.
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
"Vadym Stetsyak" <va*****@ukr.ne t> wrote: Hello, Barry!
BK> Every application runs in its own address space with its own variables, BK> unless you work hard (via shared memory or some other technique) to BK> make it otherwise.
Scope of static var can be limited to the scope of the thread via ThreadStaticAtt ribute.
The OPs question relates to multiple instances of a console application
not sharing the value of a static variable.
-- Barry
Hello, Barry!
BK> The OPs question relates to multiple instances of a console application
BK> not sharing the value of a static variable.
I've metioned that static variable can have not only application scope, but also thread scope. This notion corrects your post that it is not necessary to "work hard" to "make it otherwise". :8-)
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
>Every application runs in its own address space with its own variables, unless you work hard (via shared memory or some other technique) to make it otherwise.
Barry,
Thanks for the response!
The MSDN documentation seems to suggest that the scope of a static
member extends to a "App Domain".
Does this mean that every instance of a console app running on a
machine lives in a different App Domain?
How does the scenario change if it's an ASP.Net application?
Does every user who accesses a web application get an individual copy
of a static variable as well (or do all users of the web app share the
same app domain)?
Thanks again,
-Jonathan
>How does the scenario change if it's an ASP.Net application? Does every user who accesses a web application get an individual copy of a static variable as well (or do all users of the web app share the same app domain)?
I just answered my question with another experiment.
It appears that all users of the web application are now accessing the
same copy of the static variable.
I guess this means all instances of a web application are in the same
AppDomain.
Thanks,
Jonathan
"Vadym Stetsyak" <va*****@ukr.ne t> wrote: Hello, Barry!
BK> The OPs question relates to multiple instances of a console application BK> not sharing the value of a static variable.
I've metioned that static variable can have not only application scope, but also thread scope. This notion corrects your post that it is not necessary to "work hard" to "make it otherwise". :8-)
Well, you have to work hard to make the static variable share its
instance between applications. I'll be more clear next time.
-- Barry
"ne************ @hotmail.com" <ne************ @hotmail.com> wrote: How does the scenario change if it's an ASP.Net application? Does every user who accesses a web application get an individual copy of a static variable as well (or do all users of the web app share the same app domain)?
I just answered my question with another experiment. It appears that all users of the web application are now accessing the same copy of the static variable. I guess this means all instances of a web application are in the same AppDomain.
That is a fairly configurable aspect of ASP.NET on Win2K3 - the domains
get recycled, etc.
-- Barry
On Fri, 12 May 2006 19:59:51 +0100, Barry Kelly
<ba***********@ gmail.com> wrote: "ne*********** *@hotmail.com" <ne************ @hotmail.com> wrote:
>How does the scenario change if it's an ASP.Net application? >Does every user who accesses a web application get an individual copy >of a static variable as well (or do all users of the web app share the >same app domain)?
I just answered my question with another experiment. It appears that all users of the web application are now accessing the same copy of the static variable. I guess this means all instances of a web application are in the same AppDomain.
That is a fairly configurable aspect of ASP.NET on Win2K3 - the domains get recycled, etc.
-- Barry
You have to be careful if you rely upon a shared variable within asp.net
as the web server can still choose to load a new app domain if that is
easier for processing threads. It can also remove one to free memory if
it hasn't been used in a while. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tony Johansson |
last post by:
Hello Experts!
I have the following Array template class see below.
I execute these three statements
statement 1: Array<int> x(5);
statement 2: cin >>x;
statement 3: Array<int>::element_type y = x;
but I can't understand the last one which is
Array<int>::element_type y = x;
We have a typedef T element_type; in the template Array class see below
|
by: mlimber |
last post by:
This is a repost (with slight modifications) from
comp.lang.c++.moderated in an effort to get some response.
I am using Loki's Factory as presented in _Modern C++ Design_ for
message passing in an embedded environment with multiple processors. I
created a policy for classes, which, I had hoped, would automatically
register the class with the appropriate factory:
// In some header file...
#include <cassert>
|
by: Jeff |
last post by:
Hey
Below is a C# program I've made.... it's an app where I experiment with
variable scope. In this code you see two variables named i (one is a local
variable and the other is a member of the class). This code print out 5 (
Console.WriteLine(i); )... the member variable isn't passed on to the
Multiply, Increment variables etc.. I wonder what the rules are here... I've
been googling and and can't find a good article on variable scope in...
|
by: Luna Moon |
last post by:
I am reading the book "C++ Annotations", and here is a quote from the
book:
Namespaces can be defined without a name. Such a namespace is
anonymous and it restricts the
visibility of the defined entities to the source file in which the
anonymous namespace is defined.
Entities defined in the anonymous namespace are comparable to C’s
static functions and variables.
In C++ the static keyword can still be used, but its use is more
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |