There is code:
struct A
{
int b;
}
class B
{
A a;
int b;
}
Questions are:
- Is a in B boxed or not?
- Is a in B located in stack or in heap?
- Is b in A boxed or not?
- Is b in A stack or in heap?
- Is b in B boxed or not?
- Is b in B stack or in heap?
I really don’t understand It 🙁
1) No, there’s no boxing here.
2)
awill be on the heap, although that’s an implementation detail3) No,
binAisn’t boxed4)
binAwill live wherever the containingAwill live (so with a local variable of typeAit’ll usually be on the stack; with an instance variable of a class likeBor any static variable, it’ll be on the heap); again, this is an implementation detail5)
binBisn’t boxed either6)
binBwill be on the heap – again, an implementation detailThere’s no boxing going on here as you haven’t shown anything trying to use a value type value as a reference type value (e.g.
objector an interface).Again, the whole stack/heap distinction is an implementation detail. You should read Eric Lippert’s blog posts on the topic.