Skip to main content
added 15 characters in body
Source Link

To cut a long story short: you can't LABEL allocated memory on the dynamic heap. In static stack you can. NAME vs ADDRESS.

S T A C K A L L O C A T I O N (NAME)

Int x = 4 -> you actually do:

1 Allocate memory on stack with size of int.

2 Give this memory location NAME 'x'.

3 Put value 4 in x.

H E A P A L L O C A T I O N (ADDRESS)

Student Student1 = new Student('Peter') -> you actually do:

1 Allocate memory on Heap with size of object Student.

(You can't assign a name to this location on the heap)

2 Copy the the object's location ADDRESS into reference Student1.

3 Put value 'Peter' in the objects field

So if you can't access a location by NAME you can do it by ADDRESS.

To cut a long story short: you can't LABEL allocated memory on the heap. In stack you can. NAME vs ADDRESS.

S T A C K A L L O C A T I O N (NAME)

Int x = 4 -> you actually do:

1 Allocate memory on stack with size of int.

2 Give this memory location NAME 'x'.

3 Put value 4 in x.

H E A P A L L O C A T I O N (ADDRESS)

Student Student1 = new Student('Peter') -> you actually do:

1 Allocate memory on Heap with size of object Student.

(You can't assign a name to this location on the heap)

2 Copy the the object's location ADDRESS into reference Student1.

3 Put value 'Peter' in the objects field

So if you can't access a location by NAME you can do it by ADDRESS.

To cut a long story short: you can't LABEL allocated memory on the dynamic heap. In static stack you can. NAME vs ADDRESS.

S T A C K A L L O C A T I O N (NAME)

Int x = 4 -> you actually do:

1 Allocate memory on stack with size of int.

2 Give this memory location NAME 'x'.

3 Put value 4 in x.

H E A P A L L O C A T I O N (ADDRESS)

Student Student1 = new Student('Peter') -> you actually do:

1 Allocate memory on Heap with size of object Student.

(You can't assign a name to this location on the heap)

2 Copy the the object's location ADDRESS into reference Student1.

3 Put value 'Peter' in the objects field

So if you can't access a location by NAME you can do it by ADDRESS.

added 9 characters in body
Source Link

To cut a long story short: you can't LABEL allocated memory on the heap. In stack you can. NAME vs ADDRESS.

S T A C K A L L O C A T I O N (NAME)

Int x = 4 -> you actually do:

1 Allocate memory on stack with size of int.

2 Give this memory location NAME 'x'.

3 Put value 4 in x.

H E A P A L L O C A T I O N (ADDRESS)

Student Student1 = new Student('Peter') -> you actually do:

1 Allocate memory on Heap with size of object Student.

(You can't assign a name to this location on the heap)

2 Copy the the object's location ADDRESS into reference Student1.

3 Put value 'Peter' in the objects field

So if you can't access a location by NAME you can do it by ADDRESS.

To cut a long story short: you can't LABEL allocated memory on the heap. In stack you can. NAME vs ADDRESS.

S T A C K A L L O C A T I O N

Int x = 4 -> you actually do:

1 Allocate memory on stack with size of int.

2 Give this memory location NAME 'x'.

3 Put value 4 in x.

H E A P A L L O C A T I O N

Student Student1 = new Student('Peter') -> you actually do:

1 Allocate memory on Heap with size of object Student.

(You can't assign a name to this location on the heap)

2 Copy the the object's ADDRESS into reference Student1.

3 Put value 'Peter' in the objects field

So if you can't access by NAME you can do it by ADDRESS.

To cut a long story short: you can't LABEL allocated memory on the heap. In stack you can. NAME vs ADDRESS.

S T A C K A L L O C A T I O N (NAME)

Int x = 4 -> you actually do:

1 Allocate memory on stack with size of int.

2 Give this memory location NAME 'x'.

3 Put value 4 in x.

H E A P A L L O C A T I O N (ADDRESS)

Student Student1 = new Student('Peter') -> you actually do:

1 Allocate memory on Heap with size of object Student.

(You can't assign a name to this location on the heap)

2 Copy the the object's location ADDRESS into reference Student1.

3 Put value 'Peter' in the objects field

So if you can't access a location by NAME you can do it by ADDRESS.

deleted 539 characters in body
Source Link

To cut a long story short: you can't labelLABEL allocated memory on the heap. In stack you can. NAME vs ADDRESS.

S T A C K A L L O C A T I O N

Int x = 4 -> you actually do:

1 Allocate memory on stack with size of int. 2

2 Give this memory location NAME 'x'. 3

3 Put value 4 in x.

H E A P A L L O C A T I O N

Student Student1 = new Student('Peter') -> you actually do:

1 Allocate memory on Heap with size of object Student.   

(You can't assign a name to this location on the heap) 2

2 Copy the the object's ADDRESS into reference Student1. 3

3 Put value 'Peter' in the objects field

So if you can't access by NAME you can do it by ADDRESS.

To cut a long story short: you can't label allocated memory on the heap. In stack you can. NAME vs ADDRESS.

S T A C K A L L O C A T I O N

Int x = 4 -> you actually do:

1 Allocate memory on stack with size of int. 2 Give this memory location NAME 'x'. 3 Put value 4 in x.

H E A P A L L O C A T I O N

Student Student1 = new Student('Peter') -> you actually do:

1 Allocate memory on Heap with size of object Student.  (You can't assign a name to this location on the heap) 2 Copy the the object's ADDRESS into reference Student1. 3 Put value 'Peter' in the objects field

So if you can't access by NAME you can do it by ADDRESS.

To cut a long story short: you can't LABEL allocated memory on the heap. In stack you can. NAME vs ADDRESS.

S T A C K A L L O C A T I O N

Int x = 4 -> you actually do:

1 Allocate memory on stack with size of int.

2 Give this memory location NAME 'x'.

3 Put value 4 in x.

H E A P A L L O C A T I O N

Student Student1 = new Student('Peter') -> you actually do:

1 Allocate memory on Heap with size of object Student. 

(You can't assign a name to this location on the heap)

2 Copy the the object's ADDRESS into reference Student1.

3 Put value 'Peter' in the objects field

So if you can't access by NAME you can do it by ADDRESS.

deleted 539 characters in body
Source Link
Loading
added 77 characters in body
Source Link
Loading
added 135 characters in body
Source Link
Loading
added 135 characters in body
Source Link
Loading
added 135 characters in body
Source Link
Loading
Source Link
Loading