![]() |
![]() |
![]() |
![]() |
![]() |
|
In Java, Attraction arrays each contain a length instance
variable and several bytes of memory for the address of every
Attraction instance in the array.
Even though the instances may occupy different amounts of space, the instance addresses occupy the same amount of space. Hence, the address of the nth instance address will be offset from the beginning of the array by n times a fixed number of bytes:
*---------------------------------------------------------------------*
| |
| *-- Memory for length instance variable |
| v |
| ----------------- |
| *---*---*---*---* |
| | | | | | |
| *---*---*---*---* Memory for four addresses |
| | |
| *---------------*-------*-------*---------------* |
| | | | | |
| v v v v |
| --------------- --------------- --------------- --------------- |
| *---------------*---------------*---------------*---------------* |
| | 40827 | 69391 | 33688 | 98843 | |
| *---------------*---------------*---------------*---------------* |
| -------*------- -------*------- -------*------- -------*------- |
*--------- | ------------- | ------------- | ------------- | ---------*
| | | |
40827 v 69391 v 33688 v 98843 v
*-----------* *-----------* *-----------* *-----------*
| Instance | | Instance | | Instance | | Instance |
*-----------* *-----------* *-----------* *-----------*