How is the memory layout of a C/C++ program?

后端 未结 6 2056
感动是毒
感动是毒 2021-01-31 22:00

I know that there are sections like Stack, Heap, Code and Data. Stack/Heap do they use the same section of memory as they can grow independently? What is this code section? When

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-31 22:25

    AFAIK:

    Stack/Heap do they use the same section of memory as they can grow independently?

    They can grow indipendently.

    What is this code section?

    A read-only segment where code and const data are stored.

    When I have a function is it a part of the stack or the code section?

    The definition (code) of the function will be in the CS. The arguments of each call are passed on the stack.

    Also what is this initialized/uninitialized data segment?

    The data segment is where globals/static variables are stored.

    Are there read only memory section available?

    The code segment. I suppose some OS's might offer primitives for creating custom read-only segments.

    When I have a const variable, what is actually happening is it that the compiler marks a memory section as read only or does it put into a read only memory section.

    It goes into the CS.

    Where are static data kept? Where are global data kept?

    The data segment.

提交回复
热议问题