Data Struct for Lang.processing
-
Upload
rohit-kulkarni -
Category
Documents
-
view
225 -
download
0
Transcript of Data Struct for Lang.processing
-
8/2/2019 Data Struct for Lang.processing
1/11
Search data structures
Allocation data structures-Stacks and Heaps
Data structure for Language
Processing
-
8/2/2019 Data Struct for Lang.processing
2/11
Program Address Spacey Any program you run has, associated with it, some memory which is divided
into:
y Code Segment
y Data Segment (Holds Global Data)
y
Stack (where the local variables and other temporary information is stored)y Heap
Code Segment
Data SegmentStack
HeapThe Heap
grows
downwards
T
he Stackgrows upwards
-
8/2/2019 Data Struct for Lang.processing
3/11
Answer: a Stack
CS-3013 C-term 2008Stacks and Heaps3
y Stack a linear data structure in which items are added and
removed in last-in, first-out order.
y Calling programy Push arguments & return address onto stack
y After return,pop result off stack
-
8/2/2019 Data Struct for Lang.processing
4/11
Data structure for language
processing
y Search data Structure
y Allocation Data structure- stacks and Heaps
-
8/2/2019 Data Struct for Lang.processing
5/11
Stack (continued)
Stacks and Heaps5
y Definition: context the region of the stack that provides theexecution environment of aparticularcall to a function
y Implementationy Usually, a linear piece of memory and a stack pointer contained in a
(designated) registery Occasionally, a linked list
y Recursiony Stack discipline allows multiple contexts for the same function in the stack
at the same time
-
8/2/2019 Data Struct for Lang.processing
6/11
Stacks in Modern Systems
Stacks and Heaps6
y All modern programming languages require a stacky Fortran and Cobol did not (non-recursive)
y All modern processors provide a designated stack pointer
registery All modern process address spaces provide room for a stack
y Able to grow to a large size
y May grow upward or downward
-
8/2/2019 Data Struct for Lang.processing
7/11
Process Address Space (Typical)
Stacks and Heaps7
0x00000000
0xFFFFFFFF
Virtual
address space
program code(text)
static data
heap
(dynamically allocated)
stack
(dynamically allocated)
PC
SP
-
8/2/2019 Data Struct for Lang.processing
8/11
Stacks in Multi-threaded Environments
Stacks and Heaps8
y Everythread requires its own stacky Separate from all other stacks
y Each stack may grow separately
y Address space must be big enough to accommodate stacks for all threads
-
8/2/2019 Data Struct for Lang.processing
9/11
Stacks in Multi-threaded Address
Space
Stacks and Heaps9
0x00000000
0xFFFFFFFF
Virtual
address space
code
(text)
static data
heap
thread 1 stack
PC (T2)
SP (T2)
thread 2 stack
thread 3 stack
SP (T1)
SP (T3)
PC (T1)
PC (T3)
SP
PC
-
8/2/2019 Data Struct for Lang.processing
10/11
Heap
Stacks and Heaps10
y A place for allocating memory that is not part oflast-in, first-
out discipline
y I.e., dynamically allocated data structures that survive
function callsy E.g., strings in C
y new objects in C++, Java, etc.
-
8/2/2019 Data Struct for Lang.processing
11/11
Process Address Space (Typical)
Stacks and Heaps11
0x00000000
0xFFFFFFFF
Virtual
address space
program code(text)
static data
heap
(dynamically allocated)
stack
(dynamically allocated)
PC
SP