Click to See Complete Forum and Search --> : C++ program memory layout.


indrajit_p1
May 28th, 2008, 12:51 AM
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.

braveYOU
May 28th, 2008, 01:22 AM
Refer "Inside C++ Object Model" by Stanley B. Lippman
to know about this.

indrajit_p1
May 28th, 2008, 02:50 AM
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

laserlight
May 28th, 2008, 03:11 AM
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.

Zaccheus
May 28th, 2008, 03:24 AM
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.

Paul McKenzie
May 28th, 2008, 03:25 AM
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++ programC++ 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

indrajit_p1
May 28th, 2008, 03:25 AM
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.