views:

115

answers:

3

Hi,

I have a question to clarify my confusion about the memory organization in computer in C++.

In C++, different data is put in different location. My understanding is like this.

1) data segment section, where global and static data are located;

2) heap section, the objects created by new

3) stack section, the local variable

4) text section, the code itself.

Is that right? Is there anything I missed or did wrong?

Thanks!

+1  A: 

There are typically at least two data sections. One with initialized globals, another without (BSS). A stack section isn't typically emitted in the binary.

Of course, these kind of very implementation specific questions are kinda useless if you don't specify the implementation.

Hans Passant
Yeah very implementation specific but over 15 years I've never worked with a linker that doesn't produce at least .text, .data and .bss. I've also encountered .sdata ( for all static variables ) quite a few times too
zebrabox
+2  A: 

Here's a guide that may help.

David
+1  A: 

That question reminds me something... here is it: http://www.gotw.ca/gotw/009.htm

AProgrammer