¡latexpagebreak¿
This thing is twice in this chapter, I suppose it's not intentional (I'm reading version 28.0)
[HD Pg 225, Sec. 8.7.2 - passing-objects-to-methods]
Moderator: admin
-
- Posts: 57
- Joined: Thu Apr 15, 2021 12:21 pm
- Contact:
-
- Posts: 167
- Joined: Sun Apr 21, 2024 10:43 am
- Contact:
Re: [HD Pg 225, Sec. 8.7.2 - passing-objects-to-methods]
hello
i don't understand the image with heap space on the page 224 from the pdf version 2019
it shows 1 stack space for main method and 1 stack space for modifyData method
but this modifyData method cannot have it's own stack, since it uses the main stack after main have called it.
only a thread can have it's own stack ... not a method..?!
plz tell me what happens here:
1. main and m() will have 2 different stacks in this program
2. main and m() will share the same stack
3. m() will have a dedicated frame in the main stack (chatgpt told me this cuz i dont remember having seen something about frames before in your pdf, and chatgpt sometimes tell me that each method has it's own stack then he says the opposite... so i'm confused)
thanks
i don't understand the image with heap space on the page 224 from the pdf version 2019
it shows 1 stack space for main method and 1 stack space for modifyData method
but this modifyData method cannot have it's own stack, since it uses the main stack after main have called it.
only a thread can have it's own stack ... not a method..?!
plz tell me what happens here:
Code: Select all
public class App {
public static void main(String[] args) {
m();
}
public static void m(){
System.out.println("hello");
}
}
2. main and m() will share the same stack
3. m() will have a dedicated frame in the main stack (chatgpt told me this cuz i dont remember having seen something about frames before in your pdf, and chatgpt sometimes tell me that each method has it's own stack then he says the opposite... so i'm confused)
thanks
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 225, Sec. 8.7.2 - passing-objects-to-methods]
It is true that threads (not methods) have a stack (as explained in chapter 1.6 Stack and Heap). When a method is invoked from a thread, the space that that the method uses on that stack is called a "frame". "Stack space" is just some space on a stack.
But you are right. In the given example, both the methods will share the same stack (because they are invoked from the same thread) but their frames will be different. Thus, the spaces that the two methods use on the stack will be different. The diagram should say stack frame instead of space to avoid this confusion. But technically, it is correct because it is just referring to two different spaces on a stack. Since it does not show the space occupied by the whole stack, it looks as if these are two different stacks. This should be improved.
But you are right. In the given example, both the methods will share the same stack (because they are invoked from the same thread) but their frames will be different. Thus, the spaces that the two methods use on the stack will be different. The diagram should say stack frame instead of space to avoid this confusion. But technically, it is correct because it is just referring to two different spaces on a stack. Since it does not show the space occupied by the whole stack, it looks as if these are two different stacks. This should be improved.
-
- Posts: 167
- Joined: Sun Apr 21, 2024 10:43 am
- Contact:
Re: [HD Pg 225, Sec. 8.7.2 - passing-objects-to-methods]
tnx a lot it's very clear now i feel much better understanding this stack & heap cuz it's important for job interviews
Who is online
Users browsing this forum: No registered users and 7 guests