Other than malloc/free does a program need the OS to provide anything else?

后端 未结 7 1991
逝去的感伤
逝去的感伤 2021-02-02 02:34

I\'m working on designing the kernel (which I\'m going to actually call the \"core\" just to be different, but its basically the same) for an OS I\'m working on. The specifics o

7条回答
  •  佛祖请我去吃肉
    2021-02-02 03:30

    Are you confusing the heap and the stack?

    I ask because you mention "an ever expanding piece of memory", scope and pushing variables on the heap as they are declared. That sure sounds like you are actually talking about the stack.

    In the most common C implementations declarations of automatic variables like

    int i;

    are generally going to result in i being allocated on the stack. In general malloc won't get involved unless you explicitly invoke it, or some library call you make invokes it.

    I'd recommend looking at "Expert C Programming" by Peter Van Der Linden for background on how C programs typically work with the stack and the heap.

提交回复
热议问题