Memory allocation for global and local variables

前端 未结 3 1129
花落未央
花落未央 2020-12-13 16:29

I have learnt that memory for global variables are allocated at program startup whereas memory for local variables are allocated whenever function call is made.

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 17:02

    case 2 and case 3 would result in stack overflow as you are asking for 64 MB of stack memory wherein your stack is typically 8 MB on Linux . this would result in random bad things and /or core dumps and crashes.

    this answer greatly explains various sections of process address space (.text, .bss , .data )and how various allocations of variables is done.

提交回复
热议问题