Hi, I'm hoping some knowledgeable people can help me clear up a few
questions that popped in to my mind this morning regarding static
class members (aka class variables.)
If i have a static class member variable where does that variable
actually get allocated?
Also, at what point does the static member get allocated? Is it
created as soon as the process executes or when the first instance of
its member class is instantiated?
Lastly, does that static variable ever get deleted during execution or
only at process termination?
Thanks,
Oliver 3 2284
Oliver Chong wrote:
Hi, I'm hoping some knowledgeable people can help me clear up a few
questions that popped in to my mind this morning regarding static
class members (aka class variables.)
If i have a static class member variable where does that variable
actually get allocated?
They have static storage duration (if they actually have storage).
The actual location of that static storage in memory is implementation
and platform specific. On many systems it's called "the data segment".
Also, at what point does the static member get allocated?
At the program initialisation.
Is it
created as soon as the process executes or when the first instance of
its member class is instantiated?
As the process executes.
Lastly, does that static variable ever get deleted during execution or
only at process termination?
The latter.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
hello,
I've tried to give some of the answers to your questions
On May 22, 6:16 pm, Oliver Chong <och...@gmail.comwrote:
Hi, I'm hoping some knowledgeable people can help me clear up a few
questions that popped in to my mind this morning regarding static
class members (aka class variables.)
If i have a static class member variable where does that variable
actually get allocated?
Static class member variable are allocated in initialized .data
section. note u have uninitialized section .bss also..
well, you can also check it using objdump or nm etc.. unix utility.
Also, at what point does the static member get allocated? Is it
created as soon as the process executes or when the first instance of
its member class is instantiated?
soon as the process executes..
Lastly, does that static variable ever get deleted during execution or
only at process termination?
only at process termination..
Thanks,
Oliver
"Oliver Chong" <oc****@gmail.comwrote in message
news:11**********************@z24g2000prd.googlegr oups.com...
[...]
>
Lastly, does that static variable ever get deleted during execution or
only at process termination?
IMHO, you should consider the case when a static object is allowed to create
and destroy other objects. Think of using a reference counted pointer as a
static object:
_____________
static refcount<foog_foo = new foo;
threads_a_y() {
for(;;) {
refcount<fool_foo = g_foo;
if (l_foo) {
l_foo->foo();
}
}
}
thread_z() {
for(;;) {
refcount<fool_foo = new foo;
g_foo.swap(l_foo);
}
}
______________ http://groups.google.com/group/comp....167941d32340c6
? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: DanielBradley |
last post by:
Hello all,
I have recently been porting code from Linux to cygwin and came across
a problem with static const class members (discussed below). I am
seeking to determine whether I am programming...
|
by: Scott J. McCaughrin |
last post by:
The following program compiles fine but elicits this message from the
linker: "undefined reference to VarArray::funct" and thus fails.
It seems to behave as if the static data-member:...
|
by: Samee Zahur |
last post by:
Question: How do friend functions and static member functions differ in
terms of functionality? I mean, neither necessarily needs an object of
the class to be created before they are called and...
|
by: lovecreatesbeauty |
last post by:
Hello Experts,
Why static data members can be declared as the type of class which it
belongs to?
Inside a class, non-static data members such as pointers and references
can be declared as...
|
by: Adam H. Peterson |
last post by:
I just made an observation and I wondered if it's generally known (or
if I'm missing something). My observation is that static protected
members are essentially useless, only a hint to the user. ...
|
by: Mauzi |
last post by:
hi,
this may sound odd and noob like, but what is the 'big' difference
between static and non-static funcitons ?
is there any performace differnce?
what is the best way to use them ?
thnx
...
|
by: Matt |
last post by:
All of a sudden all my C# apps require the keyword static on all global fields and methods that I create. Even in the simplest of console apps. Can someone tell me what I have inadvertenly set in...
|
by: Kevin Prichard |
last post by:
Hi all,
I've recently been following the object-oriented techiques discussed
here and have been testing them for use in a web application. There is
problem that I'd like to discuss with you...
|
by: crjjrc |
last post by:
Hi, I've got a base class and some derived classes that look something
like this:
class Base {
public:
int getType() { return type; }
private:
static const int type = 0;
};
|
by: puzzlecracker |
last post by:
Would you quickly remind me the difference between, regular class,
static class, and nested class?
Thanks
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |