with respect to the memory

Discussion in 'C Programming' started by jesjak@gmail.com, May 23, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. In article <>,
    <> 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
     
    Walter Roberson, May 23, 2007
    #2
    1. Advertising

  3. Lew Pitcher Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    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

    iD8DBQFGVGD8agVFX4UWr64RAvI1AJ0VOhE1JKZqn7IvR1QdTiDkR9nGxgCfaqkp
    qhejG0h7hHuEs8USxsC5h7I=
    =deLg
    -----END PGP SIGNATURE-----
     
    Lew Pitcher, May 23, 2007
    #3
  4. Lew Pitcher <> 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) <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"
     
    Keith Thompson, May 23, 2007
    #4
  5. CBFalconer Guest

    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
     
    CBFalconer, May 24, 2007
    #5
  6. 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/
     
    Bart van Ingen Schenau, May 29, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper
    Replies:
    4
    Views:
    395
    Showjumper
    Jan 24, 2004
  2. John Charlois

    Roedy please respect the netiquette

    John Charlois, Jun 4, 2004, in forum: Java
    Replies:
    83
    Views:
    1,476
    Darryl L. Pierce
    Jun 14, 2004
  3. Soeren Gerlach
    Replies:
    0
    Views:
    446
    Soeren Gerlach
    Jul 15, 2004
  4. Danny
    Replies:
    8
    Views:
    13,982
    brucie
    Jul 17, 2004
  5. Ralf Wahner
    Replies:
    2
    Views:
    2,411
    Ralf Wahner
    Jul 15, 2003
Loading...

Share This Page