What is the represention for calling function in stack?












0















Today I have read an article which is about golang goroutine. It says that if there are too many recursive call, the goroutine space will be extended. In my mind, while program running, each function call will create a new stack, system only push a pointer-like object(some mechine code) which point to the created stack to caller function stack top. When cpu load this object, it will save current context and jump to created stack. After called function having returned, cpu will write the returned value which is in register back to the object. If my understanding is right, there is only a little space cast for recursive function call at calling stack. As reading that article, I doubt my understanding is wrong. May each function call make the whole called function code been pushed into calling function stack but not a pointer-like object. If this is true, a function call will cast much space at calling stack. I searched this question by google, but no result. Is there anyone can help me?



Update: I found the answer https://www.geeksforgeeks.org/memory-layout-of-c-program/.










share|improve this question

























  • There is not much stack space overhead for the single function itself, but the function being called might have a lot of local variables so each stack frame could be big, and in the case of recursion you can have a lot of those stack frames, so eventually it adds up.

    – Thilo
    Nov 24 '18 at 9:26













  • "May each function call make the whole called function code been pushed into calling function stack" The code of the function is not being pushed, but all its local variables live there.

    – Thilo
    Nov 24 '18 at 9:28











  • @Thilo 2 questions:

    – wangjun
    Nov 24 '18 at 13:40











  • @Thilo 2 questions: <1>If only local variables in stack, where is code stored in memory? There must be some place to keep code and maintain the running order of it. <2>. According to your said, if not in concurrent program, there is only 1 stack for per program(ex. the main function in C)?

    – wangjun
    Nov 24 '18 at 13:48











  • @Thilo Thanks for your comment. I think I found the answer. Earlier I deem mechine code( the text segment) is stored in stack, now your comment make me found the answer. Thank you

    – wangjun
    Nov 24 '18 at 15:29
















0















Today I have read an article which is about golang goroutine. It says that if there are too many recursive call, the goroutine space will be extended. In my mind, while program running, each function call will create a new stack, system only push a pointer-like object(some mechine code) which point to the created stack to caller function stack top. When cpu load this object, it will save current context and jump to created stack. After called function having returned, cpu will write the returned value which is in register back to the object. If my understanding is right, there is only a little space cast for recursive function call at calling stack. As reading that article, I doubt my understanding is wrong. May each function call make the whole called function code been pushed into calling function stack but not a pointer-like object. If this is true, a function call will cast much space at calling stack. I searched this question by google, but no result. Is there anyone can help me?



Update: I found the answer https://www.geeksforgeeks.org/memory-layout-of-c-program/.










share|improve this question

























  • There is not much stack space overhead for the single function itself, but the function being called might have a lot of local variables so each stack frame could be big, and in the case of recursion you can have a lot of those stack frames, so eventually it adds up.

    – Thilo
    Nov 24 '18 at 9:26













  • "May each function call make the whole called function code been pushed into calling function stack" The code of the function is not being pushed, but all its local variables live there.

    – Thilo
    Nov 24 '18 at 9:28











  • @Thilo 2 questions:

    – wangjun
    Nov 24 '18 at 13:40











  • @Thilo 2 questions: <1>If only local variables in stack, where is code stored in memory? There must be some place to keep code and maintain the running order of it. <2>. According to your said, if not in concurrent program, there is only 1 stack for per program(ex. the main function in C)?

    – wangjun
    Nov 24 '18 at 13:48











  • @Thilo Thanks for your comment. I think I found the answer. Earlier I deem mechine code( the text segment) is stored in stack, now your comment make me found the answer. Thank you

    – wangjun
    Nov 24 '18 at 15:29














0












0








0








Today I have read an article which is about golang goroutine. It says that if there are too many recursive call, the goroutine space will be extended. In my mind, while program running, each function call will create a new stack, system only push a pointer-like object(some mechine code) which point to the created stack to caller function stack top. When cpu load this object, it will save current context and jump to created stack. After called function having returned, cpu will write the returned value which is in register back to the object. If my understanding is right, there is only a little space cast for recursive function call at calling stack. As reading that article, I doubt my understanding is wrong. May each function call make the whole called function code been pushed into calling function stack but not a pointer-like object. If this is true, a function call will cast much space at calling stack. I searched this question by google, but no result. Is there anyone can help me?



Update: I found the answer https://www.geeksforgeeks.org/memory-layout-of-c-program/.










share|improve this question
















Today I have read an article which is about golang goroutine. It says that if there are too many recursive call, the goroutine space will be extended. In my mind, while program running, each function call will create a new stack, system only push a pointer-like object(some mechine code) which point to the created stack to caller function stack top. When cpu load this object, it will save current context and jump to created stack. After called function having returned, cpu will write the returned value which is in register back to the object. If my understanding is right, there is only a little space cast for recursive function call at calling stack. As reading that article, I doubt my understanding is wrong. May each function call make the whole called function code been pushed into calling function stack but not a pointer-like object. If this is true, a function call will cast much space at calling stack. I searched this question by google, but no result. Is there anyone can help me?



Update: I found the answer https://www.geeksforgeeks.org/memory-layout-of-c-program/.







stack






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 15:19







wangjun

















asked Nov 24 '18 at 8:59









wangjunwangjun

5418




5418













  • There is not much stack space overhead for the single function itself, but the function being called might have a lot of local variables so each stack frame could be big, and in the case of recursion you can have a lot of those stack frames, so eventually it adds up.

    – Thilo
    Nov 24 '18 at 9:26













  • "May each function call make the whole called function code been pushed into calling function stack" The code of the function is not being pushed, but all its local variables live there.

    – Thilo
    Nov 24 '18 at 9:28











  • @Thilo 2 questions:

    – wangjun
    Nov 24 '18 at 13:40











  • @Thilo 2 questions: <1>If only local variables in stack, where is code stored in memory? There must be some place to keep code and maintain the running order of it. <2>. According to your said, if not in concurrent program, there is only 1 stack for per program(ex. the main function in C)?

    – wangjun
    Nov 24 '18 at 13:48











  • @Thilo Thanks for your comment. I think I found the answer. Earlier I deem mechine code( the text segment) is stored in stack, now your comment make me found the answer. Thank you

    – wangjun
    Nov 24 '18 at 15:29



















  • There is not much stack space overhead for the single function itself, but the function being called might have a lot of local variables so each stack frame could be big, and in the case of recursion you can have a lot of those stack frames, so eventually it adds up.

    – Thilo
    Nov 24 '18 at 9:26













  • "May each function call make the whole called function code been pushed into calling function stack" The code of the function is not being pushed, but all its local variables live there.

    – Thilo
    Nov 24 '18 at 9:28











  • @Thilo 2 questions:

    – wangjun
    Nov 24 '18 at 13:40











  • @Thilo 2 questions: <1>If only local variables in stack, where is code stored in memory? There must be some place to keep code and maintain the running order of it. <2>. According to your said, if not in concurrent program, there is only 1 stack for per program(ex. the main function in C)?

    – wangjun
    Nov 24 '18 at 13:48











  • @Thilo Thanks for your comment. I think I found the answer. Earlier I deem mechine code( the text segment) is stored in stack, now your comment make me found the answer. Thank you

    – wangjun
    Nov 24 '18 at 15:29

















There is not much stack space overhead for the single function itself, but the function being called might have a lot of local variables so each stack frame could be big, and in the case of recursion you can have a lot of those stack frames, so eventually it adds up.

– Thilo
Nov 24 '18 at 9:26







There is not much stack space overhead for the single function itself, but the function being called might have a lot of local variables so each stack frame could be big, and in the case of recursion you can have a lot of those stack frames, so eventually it adds up.

– Thilo
Nov 24 '18 at 9:26















"May each function call make the whole called function code been pushed into calling function stack" The code of the function is not being pushed, but all its local variables live there.

– Thilo
Nov 24 '18 at 9:28





"May each function call make the whole called function code been pushed into calling function stack" The code of the function is not being pushed, but all its local variables live there.

– Thilo
Nov 24 '18 at 9:28













@Thilo 2 questions:

– wangjun
Nov 24 '18 at 13:40





@Thilo 2 questions:

– wangjun
Nov 24 '18 at 13:40













@Thilo 2 questions: <1>If only local variables in stack, where is code stored in memory? There must be some place to keep code and maintain the running order of it. <2>. According to your said, if not in concurrent program, there is only 1 stack for per program(ex. the main function in C)?

– wangjun
Nov 24 '18 at 13:48





@Thilo 2 questions: <1>If only local variables in stack, where is code stored in memory? There must be some place to keep code and maintain the running order of it. <2>. According to your said, if not in concurrent program, there is only 1 stack for per program(ex. the main function in C)?

– wangjun
Nov 24 '18 at 13:48













@Thilo Thanks for your comment. I think I found the answer. Earlier I deem mechine code( the text segment) is stored in stack, now your comment make me found the answer. Thank you

– wangjun
Nov 24 '18 at 15:29





@Thilo Thanks for your comment. I think I found the answer. Earlier I deem mechine code( the text segment) is stored in stack, now your comment make me found the answer. Thank you

– wangjun
Nov 24 '18 at 15:29












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456670%2fwhat-is-the-represention-for-calling-function-in-stack%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456670%2fwhat-is-the-represention-for-calling-function-in-stack%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'