Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 11 Arrays - Coggle Diagram
Chapter 11 Arrays
What happens in stack & heap?
Contents
with be stored in the
heap
Number address in stack will be in the stack
:!?:
Stores address in heap
The arrays
contents will be consecutive
Header
information
Max: 2^32 -1
Two dimensional arrays
Matrix:
int [][] A = new int [3][2]
First row, next column
:!!:
Intialize the array
The elements are initialized too null
Arrays.toString()
Prints the array, with closed brackets
Array: An ordered collection of values
Homogenous
Ordered and fixed length
Why fixed length?
Elements must be consecutively stored
Why an array?
Directly
accessible elements
Indices
What is 32-bits?
Misconception:
32-bits to represent the addresses
0
to
2^32-1
Only 4G
64 bits:
Size of memory address
is
48 or 64
Could we change only one bit that is stored in an address?
Each bit does does not have and address, thus this is not possible.
We cannot change a bit.
A variable(pointer to a memory address) represents a byte, not a bit
Passing arrays as parameters
All the
arrays
are considered
objects
Objects include all but PT.
Passing arrays via arguments :!?:
Memory allocation in variables
Variables are stored in the stack
Primitive type
Strings
Actually an object :!?:
Integers
Objects
Objects stored in HEAP
Hard to predetermine the size
Very little primitive DT; Most are objects and classes
Primitive != Object
Primitive stored in STACK
Size of object != Size of primitive
String is not stored in STACK;
For example if we create a stream.
S = newstring("abc")
In stack we only store the address
Array of objects/strings aren't
usually
stored in STACk
Hypothetical: Array = new int[] with three elements
Address
of array in
Stack
Actual contents in heap
int c = array[2]
200 + 4*2
Array is stored consecutively in memory
Pro: Direct access
Con: Memory wasted
Array data is stored in the heap
Must find a space large enough to accommodate the items
Freeing the data is necessary to release memory for other programs
Leads to memory fragments
Memory may be enough, but it may not be consecutive
:!!:
Initializing arrays
1.
2.
First few slides for self study