Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > with respect to the memory

Reply
Thread Tools

with respect to the memory

 
 
jesjak@gmail.com
Guest
Posts: n/a
 
      05-23-2007
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

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      05-23-2007
In article <(E-Mail Removed) om>,
<(E-Mail Removed)> 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?


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
 
Reply With Quote
 
 
 
 
Lew Pitcher
Guest
Posts: n/a
 
      05-23-2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

http://www.velocityreviews.com/forums/(E-Mail Removed) 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-----
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-23-2007
Lew Pitcher <(E-Mail Removed)> writes:
[...]
> 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) (E-Mail Removed) <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"
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      05-24-2007
(E-Mail Removed) 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

 
Reply With Quote
 
Bart van Ingen Schenau
Guest
Posts: n/a
 
      05-29-2007
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cisco doesn't respect RFC 2131 : New info about C2611 as a DHCP client sam@nospam.org Cisco 3 05-19-2005 06:34 PM
Poor Respect Treatment Shashami MCSE 5 07-20-2004 01:33 PM
Number of threads with respect to JVM memory (1.5b2 running on 2.6 linux) Soeren Gerlach Java 0 07-15-2004 11:01 AM
With respect to the data access layer, what do you all do? Showjumper ASP .Net 4 01-24-2004 09:46 PM
OT: No Respect for Rodney Keyboard Cowboy MCSE 0 07-11-2003 02:55 PM



Advertisments