Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
process memory structure
// Example program //g++ 5.4.0 #include <cstdio> //const expression constexpr const int const1 = 1; constexpr const int const2 = 2; // bss section int global1; int global2 = 0; // data section int global_init1 = 1; int global_init2 = 1; // namespace Space{ int spaceB = 0; // bss int spaceD = 1; // data }; // text section, data section void test1(){ // [text] expression printf("expr 1 addr : %p \n", &const1 ); printf("expr 2 addr : %p \n", &const2 ); // [bss] uninited data printf("global1 addr : %p \n", &global1 ); printf("global2 addr : %p \n", &global2 ); printf("spaceBS addr : %p \n", &Space::spaceB); // [data] inited data printf("inited1 addr : %p \n", &global_init1 ); printf("inited2 addr : %p \n", &global_init2 ); printf("spaceDA addr : %p \n", &Space::spaceD); } // stack void test2(){ int local1; int local2; int local3; printf("local1 addr : %p \n", &local1); printf("local2 addr : %p \n", &local2); printf("local3 addr : %p \n", &local3); } // stack void test3(){ int local1; int local2; int local3; int local[3]; printf("local1 addr : %p \n" , &local1); printf("local2 addr : %p \n" , &local2); printf("local3 addr : %p \n" , &local3); printf("local[2] addr : %p \n" , local+2); printf("local[1] addr : %p \n" , local+1); printf("local[0] addr : %p \n" , local); } // stack void test4(){ int local1; int local2; int local3; printf("local1 addr : %p \n", &local1); printf("local2 addr : %p \n", &local2); printf("local3 addr : %p \n", &local3); } // heap void test5(){ int* local1 = new int(0); int* local2 = new int(0); int* local3 = new int(0); printf("local1 addr : %p \n", local1); printf("local2 addr : %p \n", local2); printf("local3 addr : %p \n", local3); delete local1; delete local2; delete local3; } // test each function typedef void (*VFP)(); void test(const char* name, VFP fp){ printf("%s addr : %p \n", name , fp); fp(); printf("\n"); } int main() { printf("main addr : %p \n\n",main); test("test1()" , test1); // print : text section, data section, namespace test("test2()" , test2); // print : stack test("test3()" , test3); // print : stack, array test("test4()" , test4); // print : stack test("test5()" , test5); // print : heap return 0; } // stack section grow up not down // but compile on cpp.sh and code::block without Optimization // stack section grow down // with Optimization // stack section grow up // why ??
run
|
edit
|
history
|
help
0
Tubee c++
Bucket Graph Creation
ForwardListString
Test 12(2021)
2720
tes
CheckSymbolBalance
Stream6
PrePostIncrOp
typename T class T