12
1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

Embed Size (px)

Citation preview

Page 1: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

1

Programming Languages Storage Management

Cao Hoaøng Truï

Khoa Coâng Ngheä Thoâng TinÑaïi Hoïc Baùch Khoa TP. HCM

Page 2: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

2

Storage Management

• Major run-time elements requiring storage

• Major operations requiring storage to be allocated/freed

• Storage management phases

• Storage management techniques

Page 3: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

3

Run-time elements

• Code segments

• System run-time programs library routines storage management routines

• User-defined data structures

• Subprogram return points

Page 4: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

4

Run-time elements

• Referencing environments

• Temporaries in expression evaluation

• Temporaries in parameter transmission

• Input-output buffers

• Miscellaneous system data

Page 5: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

5

Run-time operations

• Subprogram call and return operations

• Data structure creation and destruction operations

• Component insertion and deletion operations

Page 6: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

6

Storage Management Phases

1. Initial allocation: allocating free storage

2. Recovery: recovering unused storage garbage collection

3. Compaction and reuse: compaction: to construct large blocks reuse: as initial allocation

Page 7: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

7

Storage Management Techniques

1. Static storage management

2. Stack-based storage management

3. Heap storage management fixed-size elements variable-size elements

Page 8: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

8

Static Storage Management

Static allocation: allocation that remains fixed through out execution.

Page 9: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

9

Stack-based Storage Management

• First Allocated - Last Freed.

• Simple storage recovery, compaction and reuse.

• Not applicable if storage needs to be allocated/freed at arbitrary points.

Page 10: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

10

Heap Storage Management

Heap: a block of storage within which data are allocated/freed in an arbitrary manner.

Page 11: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

11

heap

head

initial free-space list

heap

head

Page 12: 1 Programming Languages Storage Management Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

12

heap (storage allocated by NEW)

typical Pascal memory organization

subprogram code segmentsand system run-time routines (statically allocated) stack

bottomactivation records

free space

heap bottom