COMP 352 Data Structures and Algorithms: Recursion
COMP 352 Data Structures and Algorithms: Recursion
RECURSION
Chapter 15.1 to 15.2
1
Today
Introduction
Method Stack in JVM
Memory management
Garbage Collection
Memory Hierarchies
Computer Memory
In order to implement any data structure on an actual
computer, we need to use computer memory.
Computer memory is organized into a sequence of words,
each of which typically consists of 4, 8, or 16 bytes
(depending on the computer).
These memory words are numbered from 0 to N −1,
where N is the number of memory words available to the
computer.
The number associated with each memory word is known
as its memory address.
3
Method Stack in the JVM
How the Java virtual machine handles method invocation and return
4
Object Creation
With Java for example, all objects are
stored in a pool of memory, known as the
memory heap or Java heap (which should not
be confused with the “heap” data structure
we will cover later in the course).
Consider what happens when we execute a
command such as:
int[] items =new int[k]
A new instance of the class is created and
stored somewhere within the memory heap.
5
Free List
9
Memory Hierarchies
Computers have a hierarchy of different kinds of memories, which
vary in terms of their size and distance from the CPU.
Closest to the CPU are the internal registers. Access to such
locations is very fast, but there are relatively few such locations.
At the second level in the hierarchy are the memory caches.
At the third level in the hierarchy is the internal memory, which is
also known as main memory or core memory.
Another level in the hierarchy is the external memory, which
usually consists of disks.
10
Virtual Memory
Virtual memory consists of providing an address
space as large as the capacity of the external
memory, and of transferring data in the secondary
level into the primary level when they are addressed.
Virtual memory does not limit the programmer to the
constraint of the internal memory size.
The concept of bringing data into primary memory is
called caching, and it is motivated by temporal
locality.
By bringing data into primary memory, we are hoping
that it will be accessed again soon, and we will be
able to respond quickly to all the requests for this
data that come in the near future.
11
Page Replacement Strategies
When a new block is referenced and the
space for blocks from external memory is full,
we must evict an existing block.
There are several such page replacement
strategies, including:
FIFO
LIFO
Random
12
Today
Introduction
Method Stack in JVM
Memory management
Garbage Collection
Memory Hierarchies
13
References
These slides has been extracted, modified and updated from
original slides of :
1. Data Structures and Algorithms in Java, 6th edition. John
Wiley& Sons,
2. Java Software Structures, 4th Edition, Lewis/Chase, 2014
14