468,290 Members | 1,849 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

with respect to the memory

thanks a lot Lew Pitcher.

one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right?
so where the momory will be allocated for structure signature and for
objects?

i will be thankfull if you or someone clarify this one too

thanks

May 23 '07 #1
5 1094
In article <11*********************@w5g2000hsg.googlegroups.c om>,
<je****@gmail.comwrote:
>one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right?
so where the momory will be allocated for structure signature and for
objects?
That's going to depend upon the compiler.

No space needs to be allocated for the "structure signature"
(whatever that is exactly): the offsets of structure members
are constants, so all of the code to access them can be compiled
right into the executable.

Objects are allocated in whatever kind of storage you declared
for them -- static, auto, dynamic. The exact (or even relative)
location of these types of memory in an executable is compiler dependant.
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
May 23 '07 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

je****@gmail.com wrote:
thanks a lot Lew Pitcher.
You're welcome.
one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right?
You have the concept correct.
so where the momory will be allocated for structure signature and for
objects?
You have asked two questions here. Lets separate them so that the answers will
be clear.

Q1: Where will the memory be allocated for the structure definition?
Q2: Where will the memory be allocated for a specific declaration of an object
of a particular structure?

Question 1 is fairly simple: there is no memory allocated to a structure
definition. Period.

Question 2 is a little more complicated, and can be answered in several ways.
The pedants here might take exception to my answer, and they will provide
better, more accurate responses.

a) It depends. More specifically, it depends on whether you declare the object
as a static, an auto, or an extern, and it depends on whether or not you
provide an initializer for the contents of the object.

b) C makes no distinction between BSS and DATA. In fact, those terms have
nothing to do with C as a language. They /do/ have to do with the
implementation of your local C compiler on your local system, though. The best
we can tell you is that if you declare the object as 'static', the language
guarantees that the object will reside in the space set aside for 'static'
objects, and if you declare the object as 'auto', then the object will reside
in the space set aside for 'auto' objects. These two spaces /may/ be the same
physical space, or may be different physical spaces - that's beyond the
definition of the language.

i will be thankfull if you or someone clarify this one too

HTH
- --
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
- ---------- Slackware - Because I know what I'm doing. ------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Armoured with GnuPG

iD8DBQFGVGD8agVFX4UWr64RAvI1AJ0VOhE1JKZqn7IvR1QdTi DkR9nGxgCfaqkp
qhejG0h7hHuEs8USxsC5h7I=
=deLg
-----END PGP SIGNATURE-----
May 23 '07 #3
Lew Pitcher <lp******@teksavvy.comwrites:
[...]
b) C makes no distinction between BSS and DATA. In fact, those terms
have nothing to do with C as a language. They /do/ have to do with
the implementation of your local C compiler on your local system,
though. The best we can tell you is that if you declare the object
as 'static', the language guarantees that the object will reside in
the space set aside for 'static' objects, and if you declare the
object as 'auto', then the object will reside in the space set aside
for 'auto' objects. These two spaces /may/ be the same physical
space, or may be different physical spaces - that's beyond the
definition of the language.
I'm going to quibble about the phrase "the space set aside". There
needn't be any space specifically set aside for either static or auto
objects.

All we can really say is that static objects exist during the entire
execution of the program, and auto objects exist only during the
execution of the enclosing compound statement.

(A compiler may vary this as long as any such variation has no visible
effect; for example, a declared object might not be stored anywhere if
the program never access it, or an auto object may be stored as if it
were static if the compiler can prove that the enclosing function is
never called recursively. The latter, as far as I know, is not a
likely thing for a compiler to do, since it doesn't really save time
or space.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 23 '07 #4
je****@gmail.com wrote:
>
one more doubt i have it is: we are declaring a structure and the
memory for that structure will be allocated only when i creat some
objects to that one right? so where the momory will be allocated
for structure signature and for objects?
See the following sig. Without proper quoting and linking to
previous messages this is totally meaningless. At any rate, memory
disposition etc. is not a C language matter, and is totally
off-topic here.

--
If you want to post a followup via groups.google.com, ensure
you quote enough for the article to make sense. Google is only
an interface to Usenet; it's not Usenet itself. Don't assume
your readers can, or ever will, see any previous articles.
More details at: <http://cfaj.freeshell.org/google/>

--
Posted via a free Usenet account from http://www.teranews.com

May 24 '07 #5
Keith Thompson wrote:
(A compiler may vary this as long as any such variation has no visible
effect; for example, a declared object might not be stored anywhere if
the program never access it, or an auto object may be stored as if it
were static if the compiler can prove that the enclosing function is
never called recursively. The latter, as far as I know, is not a
likely thing for a compiler to do, since it doesn't really save time
or space.)
Actually, I have worked with a compiler which did just that.
I must admit that the compiler was not fully conforming (because
functions could not be used recursively without some extra decoration),
but the compiler would give all objects with automatic storage duration
a fixed address.
To conserve memory, would two objects that could never be alive at the
same time be allocated to overlapping memory areas.

This was a compiler for a small embedded platform (addressable memory
was 64kB)

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
May 29 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by AlexS | last post: by
12 posts views Thread by Mark P | last post: by
11 posts views Thread by Marcus Jacobs | last post: by
160 posts views Thread by RG | last post: by
70 posts views Thread by garyusenet | last post: by
113 posts views Thread by John Nagle | last post: by
11 posts views Thread by Vijaykumar Dave | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.