+ 2

(Solved)Question about Stack and Heap

I wanted to know if I really understood this so I am gonna ask. So the values of the variables of a object are stored in stack...But the addresses of all of the variables inside the stack that are from that object are referenced in the heap inside the object? Also the values of the variables in the object are in the stack only when we are using that object? I am not sure if I understand this. Edit. Ok, finally I found an answer that satisfy me: 1) https://jonskeet.uk/csharp/memory.html 2)And https://stackoverflow.com/questions/21520774/object-class-primitive-types-stack-and-heap from Eric Lippert. Other interesting sources: https://stackoverflow.com/questions/2565331/fields-of-class-are-they-stored-in-the-stack-or-heap https://stackoverflow.com/questions/5996751/is-an-int-inside-a-class-stored-on-the-stack-or-the-heap

24th Jul 2020, 4:49 PM
Ángel(🇪🇸)
6 ответов
+ 2
Stack is incremental, heap is random...
25th Jul 2020, 10:28 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
codemonkey I have not reached the New operator lesson yet, but I guess that I will understand better when I do it, thanks for the answer.
24th Jul 2020, 5:33 PM
Ángel(🇪🇸)
+ 1
If is not a problem could one more question be answered? That for example I can inside a class two functions that use a variable int called "x" means that every function(and I guess that objects) have his own stack and heap?
24th Jul 2020, 5:35 PM
Ángel(🇪🇸)
+ 1
codemonkey It does, but it only says that Stack is used to store Value type variables like int or double values and that Type ref are for objects and are stored in heap, also that object have a refecence in Stack.
24th Jul 2020, 5:50 PM
Ángel(🇪🇸)
+ 1
codemonkey Thanks, I will take a look at it.
24th Jul 2020, 5:50 PM
Ángel(🇪🇸)
+ 1
codemonkey So the variables of that new object(like his int or doubles) would be in the stack but the object itself in the heap, right?
24th Jul 2020, 5:53 PM
Ángel(🇪🇸)