Program stack and heap, how do they work?

前端 未结 5 1331
青春惊慌失措
青春惊慌失措 2020-12-23 23:09

I know that every running process has pages associated with it in virtual memory and few of them will be loaded into main memory as required. I also know that program will h

5条回答
  •  盖世英雄少女心
    2020-12-23 23:37

    3. Why stack grows down and heap grows up?

    Note that on some systems (some HP systems, for example), the stack grows up instead of down. And on other systems (e.g., IBM/390) there is no real hardware stack at all, but rather a pool of pages that are dynamically allocated from user space memory.

    The heap can, in general, grow in any direction, since it may contain many allocation and deallocation holes, so it is better to think of it as a loose collection of pages than as a LIFO-stack type structure. That being said, most heap implementations expand their space usage within a predetermined address range, growing and shrinking it as necessary.

提交回复
热议问题