473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Static class members

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

May 22 '07 #1
3 2281
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
May 22 '07 #2
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


May 22 '07 #3
"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
?

May 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
8
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:...
15
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...
6
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...
13
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. ...
3
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 ...
6
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...
11
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...
8
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; };
3
by: puzzlecracker | last post by:
Would you quickly remind me the difference between, regular class, static class, and nested class? Thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.