473,407 Members | 2,359 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,407 software developers and data experts.

Where are the static members stored in the momory?

VJ
Hi,
I apologize if this question has been asked many times on the group!

I am new to programming,
I know that there are three section in address space- one for code, one
for stack, and the third for Heap.

I just want to know how and where static members are stored in the
address space given to particular program. Is this different from the
way it is done in C?

Thanks in advance,
Jul 23 '05 #1
8 3516
VJ wrote:
I apologize if this question has been asked many times on the group!
It hasn't, AFAIK. Not many times, anyway.
I am new to programming,
I know that there are three section in address space- one for code, one
for stack, and the third for Heap.
You know that? From where? I heard those things, but then I hears also
that there exists "constant data section" and other stuff unrelated to
the subject of this newsgroup.
I just want to know how and where static members are stored in the
address space given to particular program. Is this different from the
way it is done in C?


It's probably not different [much], but it's simply unspecified where
the static data members are stored. Essentially, in the same space where
all static data resides, I believe. But what I believe is immaterial,
since it's in fact unspecified.

V
Jul 23 '05 #2
> I just want to know how and where static members are stored in the
address space given to particular program.

AFAIK the standard doesn't specifiy anything about it, so any
compiler/platform can do anything as long as it functions right. But
usually, they go into the heap - somewhere everyone can 'see' it.

Samee

Jul 23 '05 #3
sam
Samee Zahur wrote:
I just want to know how and where static members are stored in the
address space given to particular program.
AFAIK the standard doesn't specifiy anything about it, so any
compiler/platform can do anything as long as it functions right. But
usually, they go into the heap - somewhere everyone can 'see' it.

Do you meant all functions/variables goes to the heaps should be able to
be called by other classes/functions of the application?
What about private members? where they stored in the system?

Sam.
Samee

Jul 23 '05 #4
sam wrote:
Samee Zahur wrote:
I just want to know how and where static members are stored in the
address space given to particular program.

AFAIK the standard doesn't specifiy anything about it, so any
compiler/platform can do anything as long as it functions right. But
usually, they go into the heap - somewhere everyone can 'see' it.

Do you meant all functions/variables goes to the heaps should be able to
be called by other classes/functions of the application?
What about private members? where they stored in the system?


Where what is stored is *not specified*. You may stop asking about it
now.

'private' specifier only works during compile time. If you manage to gain
access to it during run-time, you should be able to see the value just
like for any other object, private or not. Access specifiers exist to
protect from programming errors, not from malicious hacking activity.

V
Jul 23 '05 #5
VJ wrote:
Hi,
I apologize if this question has been asked many times on the group!

I am new to programming,
I know that there are three section in address space- one for code, one
for stack, and the third for Heap.

I just want to know how and where static members are stored in the
address space given to particular program. Is this different from the
way it is done in C?

Thanks in advance,


Next time, try searching the newsgroup and the FAQ first.
I have answered this and other similar questions many times.

The only requirement for static member variables is that
they are stored in memory that has read and write access.
The memory could be on your computer, a harddrive, a
tape drive or a flash memory device, to name a few.

The compiler must ensure that a static member variable
has all the protection and accessibility rights according
to the standard. The standard does not tell _how_ to
do this.

The only time I really care where a variable is stored
is when I am working on an embedded system. I don't
want non-constant variables stored in ROM. I also
have to make sure that there is enough memory for
all of the variables, including temporary ones
(ones with short duration).

If the compiler wants to use stacks, heaps, linked
lists or other structures, it can. I don't care.
I'm more interested in making my program work
correctly than where the compiler places variables.

If my program is not working correctly, there is
no use bothering with optimization or worring about
where the compiler places the variables. [1]

----
1. There have been times when a piece of hardware
was stomping on the variables or when the variables
needed to be aligned and weren't. This is when
I need to know where the variable is stored.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Jul 23 '05 #6
hi everyone i`m a first timer on groups.
from what i`ve infered your statement that "static data can be stored
on the stack" does not fit.
static data area is the place where the computer stores the static data
where its values are to remain the same for the different instances of
the variable.another thing ; the static datamembers of the class are to
be initialized during the compilation time the same area also stores
the initialized global data also.
static data members also have fixed memory address once the program has
been loaded into the memory.
One more thing if we could store the data in the stack then the basic
requirment that the static data should keep its value during function
calls would fail during recursive function calls where the stack
pointer will be moved down by the function and it will over-ride the
previous value.

Jul 23 '05 #7
sam
Thomas Matthews wrote:
VJ wrote:
Hi,
I apologize if this question has been asked many times on the group!

I am new to programming,
I know that there are three section in address space- one for code,
one for stack, and the third for Heap.

I just want to know how and where static members are stored in the
address space given to particular program. Is this different from the
way it is done in C?

Thanks in advance,

Next time, try searching the newsgroup and the FAQ first.
I have answered this and other similar questions many times.

The only requirement for static member variables is that
they are stored in memory that has read and write access.
The memory could be on your computer, a harddrive, a
tape drive or a flash memory device, to name a few.

The compiler must ensure that a static member variable
has all the protection and accessibility rights according
to the standard. The standard does not tell _how_ to
do this.

The only time I really care where a variable is stored
is when I am working on an embedded system. I don't
want non-constant variables stored in ROM. I also
have to make sure that there is enough memory for
all of the variables, including temporary ones
(ones with short duration).


With embedded system, how can you make sure those non-const variables
are not writing to ROM? If there is RAM in the embedded system, aren't
all variables (including const and non-const) created in RAM by default?

Sam
If the compiler wants to use stacks, heaps, linked
lists or other structures, it can. I don't care.
I'm more interested in making my program work
correctly than where the compiler places variables.

If my program is not working correctly, there is
no use bothering with optimization or worring about
where the compiler places the variables. [1]

----
1. There have been times when a piece of hardware
was stomping on the variables or when the variables
needed to be aligned and weren't. This is when
I need to know where the variable is stored.

Jul 23 '05 #8

sam schreef:
th short duration).

With embedded system, how can you make sure those non-const variables are not writing to ROM? If there is RAM in the embedded system, aren't all variables (including const and non-const) created in RAM by

default?

AFAIK, no. AFter all, const variables must be initialized. i.e.
const int i; // no value yet
is illegal. There's always an initial value, e.g. 42. Now, this must
obviously be stored in the ROM of an embedded system, or else it will
be gone on powerloss (same as the code, must be in ROM too). Now, why
would you relocate the variable from ROM to RAM? There's nothing in
C++ that requires such a copy. (one exception: embedded systems with
separate memory spaces, in which ordinary pointers can't refer to ROM.
That's moee related to the CPU than C++, IMO )

Regards,
Michiel Salters

Jul 23 '05 #9

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...
1
by: Nicky | last post by:
Hello, Maybe a stupid question. In my component on the servermachine I have some objects that are static. They are serveractivated. At compiletime of the clientsource, he gives me an...
4
by: fred | last post by:
Hi, can someone please explain to me how a static member of a class works. For example if I have: public Class1 public static Class2 myClass2 = new Class2; public static Int16 thisValue = 200;...
9
by: thomson | last post by:
Hi all, Would you please explain me where will be the heap stored if it is declared inside the Class, As class is a reference type, so it gets stored on the heap, but struct is a value...
5
by: rettigcd | last post by:
I have several classes that all have the same static member: class A{ public static string Table = "TableA"; } class B{ public static string Table = "TableB"; }
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...
2
by: tconti | last post by:
Hello: We have an application that generates a static database layer based on stored procedures defined in SQL Server for consumption by client applications. These classes contain a slew of...
9
by: Chuck Cobb | last post by:
I am creating some static classes with static methods and static variables, but I have a question: What is the lifetime of static classes and static variables? Is there any risk that these...
15
by: archana | last post by:
Hi all, can anyone tell me differene between public static and private static method. how they are allocated and access?. thanks in advance.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
agi2029
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 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.