CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2007
    Location
    Calcutta, India
    Posts
    95

    C++ program memory layout.

    Just like a C program memory is divided into four parts: data segment, code segment, stack and heap, I want to know if a C++ program has the same kind of memory layout (in my knowledge the answer is yes, but my knowledge is very very limited)? does it have some other segment outside of the above four? and where are the vtables stored?

    I have tried searching the net for an answer to this but didn't find anything relevant. There is a lot of material on Object memory layout but not this.

    Will appreciate all informed discussion.

  2. #2
    Join Date
    Apr 2004
    Location
    Bangalore
    Posts
    86

    Post Re: C++ program memory layout.

    Refer "Inside C++ Object Model" by Stanley B. Lippman
    to know about this.
    Indranil
    Never forget to add reputation if the post is useful.
    u never know when u make a miracle so go on exploring...

  3. #3
    Join Date
    Sep 2007
    Location
    Calcutta, India
    Posts
    95

    Re: C++ program memory layout.

    Quote Originally Posted by braveYOU
    Refer "Inside C++ Object Model" by Stanley B. Lippman
    to know about this.
    someone please, PLEASE tell me where to say this so that everybody gets to hear it. mod, maybe this should be a part of forum answering guidelines.

    I have complained about this n times before and doing so once again. ANYONE ATTEMPTING TO ANSWER A QUESTION MUST READ IT WITH ATTENTION AND BE ABSOLUTELY POSITIVE THAT HE/SHE UNDERSTANDS WHAT IS BEING ASKED BEFORE POSTING A REPLY. if there is a difficulty in understanding the exact question then please post a request for clarification.

    I have specifically made it clear in my post that I am looking for the program memory layout as opposed to the object memory layout and someone comes along with a reply to that post refering to "Inside the C++ Object Model" by Lippman, which incidentally I started reading a week back and is on the verge of completing right now.

    nowhere in that book, does Lippman devotedly talks about the program memory layout (and neither do I think the answerer means one can find that in this book).

    Please (I repeat) read the question carefully.
    I

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: C++ program memory layout.

    I also have limited knowledge in this area, but from what I understand, this is platform dependent, but what you have listed is typical. I reason that it is platform dependent since it is not dictated by the C and C++ standards (if I am not wrong), and you probably could find out by getting the compiler to output in assembly.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: C++ program memory layout.

    I agree with laserlight, it is implementation dependent.

    As I understand it, both C and C++ only describe how the program should behave, the language says little or nothing about how the behaviour is achieved.
    My hobby projects:
    www.rclsoftware.org.uk

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: C++ program memory layout.

    Quote Originally Posted by indrajit_p1
    Just like a C program memory is divided into four parts: data segment, code segment, stack and heap, I want to know if a C++ program
    C++ is a programming language. All that is specified are the rules of the language. It has no specification on the "layout" of the final executable program. That's why you haven't found anything.

    In the C++ specification, you won't find terms such as "data segment", "code segment", "heap", or vtables. The only reference to "stack" is in terms of the std::stack container.

    What you want to look for is the way your particular compiler/linker/OS lays out an executable program.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Sep 2007
    Location
    Calcutta, India
    Posts
    95

    Re: C++ program memory layout.

    Laserlight,

    err...I don't know Assembly. but thanks for u'r thoughts on this anyway.

    I

    p.s.: Zachheus and Paul, thanks for clarifying the issue for me.
    Last edited by indrajit_p1; May 28th, 2008 at 03:28 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured