class A {
int i;
class B {
char c[1024];
};
};
When we call "A* myA = new A()" the memory looks like this:
- 4 bytes in heap allocated, B was instantiated/allocated
When we call "A myA = A()", the memory looks like this:
- 4 bytes in stack allocated, B was instantiated/allocated
class A {
int i;
class B {
char c[1024];
} myB;
// the same as
// B myB;
};
When we call "A* myA = new A()" the memory looks like this:
- 4 + 1024 bytes in heap allocated, B was instantiated/allocated
When we call "A myA = A()", the memory looks like this:
- 4 + 1024 bytes in stack allocated, B was instantiated/allocated
No comments:
Post a Comment