Aho, Sethi, and Ullman - PowerPoint PPT Presentation

1 / 66
About This Presentation
Title:

Aho, Sethi, and Ullman

Description:

236360 8 Aho, Sethi, and Ullman Chapter 7 Cooper and Torczon Chapter 6 – PowerPoint PPT presentation

Number of Views:1582
Avg rating:3.0/5.0
Slides: 67
Provided by: bilh
Category:

less

Transcript and Presenter's Notes

Title: Aho, Sethi, and Ullman


1
???? ?????????? 236360????? 8 ????? ??? ?????
Aho, Sethi, and Ullman Chapter 7 Cooper and
Torczon Chapter 6
2
????? ??? ???? (Runtime)
  • ??? ????? ???????? ?"? ????????? ?????? ??????
    ??????? ????? ?? ???? ???.
  • ???? ????? ??????, ????? ?????? ??????, ???????
    (?????? ????? ?????, ????? ??????? ????"?),
    ?????? ??? ????? (?????????), ????"?.
  • ???? ????? ?? ?? ????????? ?????, ??? ??? ????
    ????? ????? ?????. ?? ???? ?? ??? ????? ????.
  • ??????? ???????? ???? ?????? ?? ????? ???????
    ??????? ?????? ???????? ?????.
  • ??? ???? ?? ?????? ??? ????? ????? ???? ??????
    ?????? ??????.
  • ???? ?????? ??????? ????? ????? ??????? ?????.

3
????? ?????? ?????? ????
  • ?? ???? ??? ??? ?????? ??? ????
  • 236780 "?????????? ?????? ?????? ??????"

4
?????? ?????? ?????????
  • ?????? ???????? ????????? ?????? ?? ???????.
  • ????? ?????? ??? ????? ????? ???? ?????? ?"?
    ?????????.
  • ????? ?? ???? ?????? ???? ?????, ???? ????? ?????
    ?????? ?????? ?? ???? ????.
  • ????? ??? ?????? ???? ?? ???? ????? ????? ?????
    ???????.
  • ???? C ????? ????? malloc ?????? ???? ??????
    delete ?????? ????? ???? ??????? ?? ????.

Ptr malloc (256) / Use ptr / Free (Ptr)
5
????? ?????? ??????
  • ?-Java ??????? ?????? new ???????? ???? class
    ?????.
  • President obama new President
  • ??? ?????? ????? ?? ???????? ?-Java ?????? ??????
    ????? ??????? ?"? garbage collector ????????? "??
    ????? ???? ????".

course c new course(236360) c.class TAUB
2 Faculty.add(c)
6
????? ?????? ???? ????????
  • ????? ?????? ??? ?????? ????? ??? ???? ?????
    ????? ???? "????" ????? ?????? ?? garbage
    collector ???? ???????.
  • ????? ????? ???? ??? ????? ????? ????
  • Memory leaks
  • Dangling pointers
  • ????????? ?????? ???? ????????? ???????
    ??????????? ????? ?? ?????? ??? ?????? ?????? ???
    ???????? ??? ?? ????.
  • ????? ???? ?????? ?? ???? ?-80, ?????? ?"?
    garbage collection. (?? ????? ?????? ?????)

7
????? ?????? ???????
  • ???? ?????? "?????" ???????? ?? ????? ????
    ????????, ??? ????? ?? ???? ???.
  • ?? ???? ???? ???? ?? ??. ?? ?? ??? ????? ?? ????
    ??? ??-??? ???? ???? ????.
  • ??? ??????? ?????? ?????????? ??????? ???????
    ???? ??????? ???? ?????? ???? ????.
  • ?? ???? (reachable) ?????? ?? ???????? ?????????
    ????? ?? ??????? ???? ?????.
  • ?????? (roots) ??????? ??????? ?? ??????? (??
    ???????), ??????? ???????? (?-class), JNI, ???'.
  • ???? ?? ?????? ??????? ?? ???? (??????? ?"?
    ?????????), ?? ?????? ??????? ??? ??????? ??? ??
    ????, ?"? ????? ???? ??? ?????? ???? ??????.

8
??????? ?? ????? ?????? ???????
  • ????? ?????? ????????? ?? ??? ?????????.
  • ??? ???? ????, ????, ????? ?????? ??? ???????.
  • ???? ??????, ???? ??? ?????, ???? ??????.
  • ??'???? ??????? ?? ??????? ???? ?? "????" ??
    ????????.

????? ????? ??????
  • ?????? ?? ????? ???? Java, C, Lisp.
  • ?????? ?? ???? ????? delete.
  • ?????? ?? ????? ???? C, C.
  • ?????? ???? ?"? ???????? ????? (????, GCalloc
    ????? Malloc) ??????? ????? ????????? ????? ???
    ?? ????.

9
?? ?? ?????? ????????
  • ?????? ??? ??????? ?? ????.
  • ??"? ???? ????? ??? ???? ???? ????? ?????.
  • ??????? Lisp ?????? (???? ?-60) ????? ???? 40
    ???? ?????, ???????? ?????? ??? ??? ??????.
  • ???? ??'????, ????? ??? ???? 10 ???? ?????,
    ???????? ?? ??????? ?????.
  • ???????? ?????? ??? ???? ?-60. ??? ????? ?? ??
    ??????????? ????????.

10
?????? ?? ??????
  • ??? ???? ?? ?????? (??"? ???? ???? ?????),
  • ???? ????? ?? ???? ???????
  • ???? ?????? ????? ?? ??? ?????? ???????
  • ???? ???? ???? ???? ??????
  • ??????? cache Locality.

11
????? ?????????? ???????
  • ???????? ????? ??????? (reference counting)
  • ???????? ??? ????? (mark and sweep)
  • ??? ???????? ??? ????? (mark-compact).
  • ???????? ????? (copying)
  • ??? ???????? ?????? ?? ????????? tracing ???? ???
    ?????? ?? (?????? ??) ?? ?????????? ???????.

12
???????? ????? ??????? Reference Counting
  • ????? ??? reference-count ??? ??????? ???
    ??????? ??????? ?? ????????.
  • ???? ??? ??? ?? ????? ?? ???????? (rc0) ??
    ???????? "??" ?? "?? ????" ????? ????? ????.
  • ???????? ????, ??????? ?? ????? ?????? ??????.

13
????????? ??????
  • Each object has an RC field, new objects get
    o.RC1.
  • When p that points to o1 is modified to point
    to o2 we execute o1.RC--, o2.RC.
  • if then o1.RC0
  • Delete o1.
  • Decrement o.RC for all children of o1.
  • Recursively delete objects whose RC is
    decremented to 0.

p
o1
o2
14
???? ?? ???? ?????? ????? ?????? !
  • ?? ???? ????? ???? ????? ????.
  • ??????? ??????? ???????? "????????" ??? ????
    ??????, ??? ????? ?? ????? ????.
  • ?????? ??? ????? ?????? ?????? ???????? tracing
    ????? ????? ????? ??????.
  • ?????? ????? ?????????? ???????? ?????? ??????.
  • ?? ????? ?? ???? ????? ??.
  • ???? ????? ????? ???????? ????????. ???? ??????
    ??.
  • ???? ????? ??? ?"? ?????????? ???? ???????.

15
???????? Mark and Sweep
  • ??? ?????? (Mark)
  • ???? ???????? (roots) ????? ?? ?? ??????????
    ??????? ??? ?????? ?? ???????.
  • ??????? ?-BFS ?? DFS.
  • ??? ?? ??????? ?????? ??????.
  • ??? ?????? (Sweep)
  • ???? ?? ?? ?????????? ?-heap
  • ???? ?? ?? ?????????? ???-??????? ?? ????? ??????
    ????????.

16
The Mark-Sweep algorithm
  • Traverse live objects mark (black).
  • Unmarked (white) objects can be reclaimed.

registers
Note! This is not the heap data structure!
Roots
17
Triggering
?? ????? ?? ??????? ????????...
  • New(A)
  • if free_list is empty
  • mark_sweep()
  • if free_list is empty
  • return (out-of-memory)
  • pointer allocate(A)
  • return (pointer)

18
??????????? ???????? ??????
mark(Obj) if mark_bit(Obj) unmarked mark_bit(
Obj)marked for C in Children(Obj) mark(C)
mark_sweep() for Ptr in Roots mark(Ptr) sweep()
Sweep() p Heap_bottom while (p lt Heap_top) if
(mark_bit(p) unmarked) then free(p) else
mark_bit(p) unmarked ppsize(p)
19
?????? ?? Mark-Sweep
  • ??? ??????????? ??????? ??????? ????? (??"? ?????
    ?????? ????).
  • ???? ?????
  • ?? ???? ????????? ???? ????? ?????????.
  • ????????
  • ??? ?????? ???? ?? ?????????? ????? (????
    ?????????).
  • ??? ?????? ???? ?? ?? ?-heap.
  • ????? ???? ?? ?????? ???? ??? ??? ??? ?????.
  • ?? ???? ?????? ??????? ??????? ?? ????????
    ????????

20
??? ????? Mark Compact
  • ???? ?????, ????????? ?????? ???????.
  • ?? ???? ????? ?????????.
  • ???? ???? ??? ?????????, ?????? compaction.
  • ?????? ?? ?? ?????????? ????? ?? ????? ?-heap
    ???????? ?? ?? ????????? ?-heap ???????? ??????
    ?? ??????? ?????????.
  • ?-compaction ???? ??? ??? ????? ?????? ???? ?????
    ??? ???????
  • ???? ???? ?????? ??????, ??
  • ???? ???? ????? ????.

The Heap
21
????? ????????? ????? ???????? ?????????
  • ???? ?????? ?? ???????? ?????????
  • ???? ?? ?-heap ???? ??? ??????? ?? ??? ??? ????.
  • ???????? ???? ?????? ?????? ?? ????? ???? ????
    ?????? ????? ????? ?-heap.
  • ???? ?? ????? ?? ?? ??????? ????? ?????.
  • ???? ?? ?-heap ???? ?? ??????? ?? ????? ????.
  • ??? ??????? ???????, ?????? ?? ???????? ???
    ??????? ???? ??? ?????.
  • ??? ?? ???? ????? ??? ???? ?????, ???? ???? ?????
    ?????? ?? ?-heap?
  • (????????? ???? ????? ???? ?????, ????? ????
    ?????? ????? ???????, ????????? ???????)

22
??? ????? Mark Compact
  • ??????? ???????? ?? ?????????
  • ??? ???? ?? ?????????? ?????
  • ??? ???? ?????? ?????? ?????? ????? ?????? ??
    ??????
  • ??? ????? ???? ????? ?? ?-heap?
  • ??? ?? ??? ?????? ????? ????? ?"? ????? ???????
  • ?? ????? ????? ??.

The Heap
23
???????? ?????? (Copying)
1
2
  • ?-heap ????? ???? ?????.
  • ???? ?????? ???? ?? ?? ?????? ???????.
  • ???? ???? ???? ???? ??????.
  • ???? ??????, ?????? ?? ?? ?????????? ???????
    ???????? ???? ????? ???? (?????).
  • ???? ?????? ?????? ?????? ???????.
  • ????? ???? ???? ????? ?????? ?? ?????????? ?????
    ???? ????? ??????? ????? ?????? ?????.
  • ????? ????? ???? ??? ????? ?? ?????? ???.

24
Copying garbage collection
Part I
Part II
B
A
Roots
C
D
E
25
???? ??????...
Part I
Part II
A
C
B
A
Roots
C
D
E
26
Roots are updated Part I reclaimed.
Part I
Part II
A
C
Roots
27
??????
  • ????? ?????? ?????
  • ?????? ????? ??? ??-heap ?? ?????.
  • ????????? ????? ????? ?????????? ?????
  • ???? ???? ?? ?????????? ????
  • ??"? ?? ?????????? ?????? ????, ???? ?? ?????
    ???????? ??? ??? ?????????? ??????? ??????? ??
    ???? ??? ????? ???????? ??????.

28
?????? ?????? ?????
Copying Mark sweep Reference Counting
Live objects Size of heap (live objects) Pointer updates dead objects Complexity
Half heap wasted Bit/object stack for DFS Count/object stack for DFS Space overhead
For free Additional work Additional work Compaction
long long Mostly short Pause time
Cycle collection More issues
29
?????? ??????? ????
  • ??????? ??????? ?? ??????? ?????????
  • ???????? ?? ????????
  • ?????? ???? ?? ??????? ?????? ??????, ??
  • ?????? ????? ?????? ????? ??????
  • ??????? ?-cache
  • Real-time

30
?????? ????? ?????
  • Heap, objects
  • Allocate, free (deallocate, delete, reclaim)
  • Reachable, live, dead, unreachable
  • Roots
  • Reference counting, mark and sweep, copying,
    tracing algorithms
  • Fragmentation

31
?????? ?????? ??????? ?????? ?????????
  • (???? ??? ?? runtime ????? ?????)

32
??? ?????? ??????????
  • ??? ?????? ?????? ????????? ???? ????, ???? ?????
    ?? ???? ??? ??????.
  • ????? ??????? ?????????, ??? ????? ?? ??????
    ?????.
  • ????? ?????? ???? (return address)
  • ???? ??? ??????? ????? ???????? ?????
  • ????? ??????? ???????? (?? ???? ???? ????????
    ??????? ???????? ???????)
  • ????? ?????? ???????
  • ???? ????? ???? ???? (scope).

33
Dynamic vs. Static Scope
  • ??? ????? ????????? ??? C, ?????? ??? ?? ?????
    ??????? ??????? ???? ??"? ???? ??????? (?????
    ????).
  • ????? ???? ?????? ???? ?? ????? ?????? ??? ???
    ?????? ????? ?????? ??????? ??? ?????? ?????.
  • ????? ???????? ??? C, C, Java, ???? ?????
    ???????? ?"? ?????? ??? public, private,
    protected.

34
????? ?-scope ????
main ( ) int a 0 int b 0 int b
1 int a 2 printf (d d\n, a,
b) int b 3 printf (d d\n,
a, b) printf (d d\n, a, b)
printf (d d\n, a, b)
  • ?????? ??? ?? ?????? ??????? ?? ???? ?????.
  • static scoping ?????? ?????? ?????? ?????.

B2
B0
B1
scope ?????
B0, B1, B3 a0
B0, b0
B1, B2 b1
B2 a2
B3 b3
B3
B3
35
????/? ????/? x, ??? ??/? ??????/???
  • ?? ????? ??????? ?????
  • var x int
  • function foo() int return x
  • function bar() int var x int
  • x 1
  • return foo()
  • procedure main() x 0
  • print bar()

36
?????? ???????
  • ??????? ????? 0
  • C, ????, C, Java ???? ????? ?"????????" (x
    ????? ?????)
  • ??????? ????? 1
  • LISP, APL, Perl (??????), (x ????? ???????)
  • ??????? ????? ????? ????? ?? ????? ??? ?????
  • PHP

37
????? ???? ??????? ??"? dynamic scoping
  • ??? ?? ?? ?????? (???? ????).
  • ???? ???? hash table ?? ????.
  • ????? ?-scope ??? ????? ????? ????? ?? ??????
    ???????.
  • ????? ?-scope ??? ????? ????? pop ????????.
  • ???? ?????? ??? ??? ???????.
  • ??? ???? ????? ????? ?? ?????? (??????? ??
    ??????) ???? ??????????
  • ?? ???? ?????? ????????

38
????? ???? ??????? ??? static scoping
  • ?????? ???? ?????? ???? ???? ???? ?????????.
  • ???, ????? ?? ?????? ??? ???? ??????.
  • ????? ?????? ??????? ??? ??? ?????? ??????????.
  • ??? ?????? ???-???? ?? "???? ?????? ?? ????".
  • ???? ????? ????? types.

39
????? ????? ?"? ????
  • ????
  • var x int
  • function foo() int return x
  • function bar() int var x int
  • x 1
  • return foo()
  • procedure main() x 0
  • print bar()

?? ????? ??????? ?????
x (??????) 432234
x (???? bar) 432238
40
???? ?????? ?????? ??????? (????? ?? ?????).
  • ?? ?????? ?? ?????? a (?????? ?-fib) ?????? ?????
  • procedure fib(n int) var a int
  • var b int
  • if (n 1) return 0
  • a fib(n 1)
  • b fib(n 2)
  • return a b
  • procedure main() print fib(5)
  • ???? ?? ??? ?????? ?? ????? ????? ?? dynamic
    scoping.

41
????? ??????? (?????????)
code
static data
stack
?

?
heap
?????? ????????
???? ?? ???? ???? ?????????
??????? ???? ????? ???? ????. ??? ????? ??????
????? (activation records)
top of stack ?
????? ?????? ??????? ???? ????
42
?????? ?? ?????? ???????
  • ??? ????? ?????????, ??????? ????? ????? ???????
  • ??? ?????, ?????? ????? ?????
  • ?????? ??????? ?? ??? ?????? ?????? ?? ??
    ????????
  • ????? ?? ????? ????? S-a
  • S ??? ????? ??? ??????? ????? ???? ????
  • a ??? ?????? ?????? ?? ?????? ??????
  • ??????? ??????? ?????? ???? ?????????!

43
????? ????? ?? fib
??????? ?? ?????? ???????.
other parts of activation record n (addr
S-20) a (addr S-16) b (addr S-12) other parts
of activation record
Stack Pointer (S)
other parts of activation record n (addr
S-20) a (addr S-16) b (addr S-12) other parts
of activation record
Stack Pointer (S)
other parts of activation record n (addr
S-20) a (addr S-16) b (addr S-12) other parts
of activation record
Stack Pointer (S)
44
?? ??? ?? ?????? ??????
??? ????? ?????? -- ?????? returned value
??????? ????????? ?????? ???????? actual parameters
????? ?????? ?????? ?? ????????? ?????? optional control link
???? ?????? ?? ??? ??????? ??????? ?? ??????? (display) optional access link
??? ?????? ???? ????? ?????? ?? ????????? ??????? saved machine status
?????? ??????? local data
???? ?????? temporaries
45
?? ??? ?? ?????? ??????
  • ??? ????? ????????? ?????? ???? ???? ???????
    ??? ?? ???????
  • ????? ????? ???????, ????? ???? ??? ????? (int
    ???? ???????, struct ??)
  • ???????? ?????????? (???? ????????) ???????
    ??????? ??-??? ???????? ??????
  • ??? ?????? ???? ????? ?? ????? ?????
  • ???? ?????? ?????, ?????? ??????? ?????????? ???

46
????? ????? ?? ?????? ?????
. . .
parameters and returned value
control link
links and saved status
temporaries and local data
parameters and returned value
control link
links and saved status
temporaries and local data
  • ?????? ?????? ????? ???? ?????? ??????? ????
    ?????????
  • ?????? ?????? ?? ???? ???? ????? ??"? ?? ????
    ?-heap ?? ?? ???.

top_sp
47
????? ??????
. . .
parameters and returned value
control link
links and saved status
temporaries and local data
parameters and returned value
control link
links and saved status
temporaries and local data
  1. ????? ???? ?? ???????? ??????????
  2. ????? ???? ?? ????? ????? ??? ???? ?????? ??
    top_sp
  3. ????? ???? ?? top_sp
  4. ????????? ?????? ????? ?? ????????? ??? ??? ?-
    status information
  5. ????????? ?????? ?????? ?? ??????? ??????? ?????

/
top_sp
3
48
????? ?????
. . .
parameters and returned value
control link
links and saved status
temporaries and local data
parameters and returned value
control link
links and saved status
temporaries and local data
  1. ????????? ?????? ?????? ?? ???? ?????? ?????
    ??????
  2. ????????? ?????? ?????? ?? top_sp , ?? ????
    ?????????, ??? ?- status information
  3. ????? ?- top_sp ?????, ???? ???? ???? ??????

,3
top_sp
49
????????? ???? ????????? ????
  • ?????, ?????? (program) ?????? ????? ?? ?????
    (procedure ?/?? function)
  • ??? ???? ?????? ????? ??-?????
  • ?? ??-???? ????? ???? ??? ?? ?????? ?-scopes
    ??????? ???? ?? ?? ?????? ???? ????

50
????????? ???? ????????? ????
???? ?????? ?????? p?a?a?c?b?c?d
  • program p
  • var x Integer
  • procedure a
  • var y Integer
  • procedure b beginb end
  • function c
  • var z Integer
  • procedure d begind end
  • begincend
  • begina end
  • beginp end.

?? ?????? ?? ????? y ???? ????????? d?
51
????? ????? ??????
  • ???? ????? ????, ??, ?? ????? ????? (???? ??
    ????).
  • ????? ???? ?? ??? ?????? ??????? ????? ??????
    ??????.
  • ???? c ?????? ??????? ?? a. ???? a ????
  • ??? ?????? ???? ???? ?? ????? ?????? ??????? ??
    ??????? ????????? ???????
  • ???? ????? ?? ??????? ??? ????? ??????? ??????
    ???? ????? ?????.
  • ???? ?? ????? ????? ?????? ??????? ?????? ??????
    ????? (?? ????? ????? ???? ??????? ???????, ??

P
P
a
a
P
a
b
P
c
P
c
P
d
P
d
52
????? ????? ??????
  • ???? ????? ????, ??, ?? ????? ????? (???? ??
    ????).
  • ????? ???? ?? ??? ?????? ??????? ????? ??????
    ??????.
  • ?? ?????? ???? k ????? ??????? ???? k ?? ???
    ?????? ??????? ?? ???? ??? ??.
  • ?? ??? ?????? ?????? ???? j ???? jltk, ?? ?? ?????
    ????? ??????? ??????? ?????? ???? ????? j.
  • ????? 1 ?? ??? ??????? ???? j ?? ??????? ?? ???
    ????? ????? ?? ????? ?? ??????? ??????? (????
    ?????? ??????????).

53
????????? ???? ????????? ????? ?-access link.
  • ????? ???? ????? d ????? ???? ?????? ?? ????? c
    ?????? ???? ?????. ??? ?????? ?? ??????? ?? c?
  • ?????? access links ?????? ??????
  • ?? access link ???? ????? ?????? ?????? ???????
    ?? ??? ?????? ??????
  • ????, ?-access link ?? d ???? ??????? ??????
    ?????? ?? c.
  • ?-access links ????? ???? ????
  • ???? ?-links ????? "?????" ???? ???? ?????????
  • ???? ??? ???? ?????? ???? ????? ???? ???????
    (?????) ??? ??????? ??????? ??????? ??? ?????
    ??????.
  • ???? ??? ????? ??????? ???? ????? ??????? ??????
    ??????? ????? ????? ???? ????.

54
????? ?-access links
a
y
a
y
c
z
b
c
z
d
55
????? ???? ?? ?-access links ???? ????
  • ????? ???? (Display) ????? ?????? ????? ??? ??? i
    ?? ????? ??????? ??????? ???? ????? i ???????.
  • ?????? ?????, di ????? ?????? ?????? ??????
    ????? ?? ???????? ????? ????? i.
  • ?????? ????? ??????? ???????? ??????, ?????
    ???????? ?? d. ?? ???? ??????.

56
????? ???? ?-Display
s
d 1
d 2
  • ???????? ???????? ???? ????? i ?????? ?? ??????
    ???
  • ?????? ?? ???? ?? di ?????? ?????? ????? (????
    ??? ??????? ?????? ????????).
  • ??????? ?? di ?????? ?? ????? ?????? ?????
  • ?????? ?????????? ?????? ?? ?????? ?????

q(1, 9)
access link
57
????? ???? ?-Display
s
d 1
d 2
  • ???????? ???????? ???? ????? i ?????? ?? ??????
    ???
  • ?????? ?? ???? ?? d i ?????? ?????? ?????
  • ??????? ?? d i ?????? ?? ????? ?????? ?????
  • ?????? ?????????? ?????? ?? ?????? ?????

q(1, 9)
saved d 2
q(1, 3)
saved d 2
58
????? ???? ?-Display
s
d 1
d 2
d 3
  • ???????? ???????? ???? ????? i ?????? ?? ??????
    ???
  • ?????? ?? ???? ?? d i ?????? ?????? ?????
  • ??????? ?? d i ?????? ?? ????? ?????? ?????
  • ?????? ?????????? ?????? ?? ?????? ?????

q(1, 9)
saved d 2
q(1, 3)
saved d 2
p(1, 3)
saved d 3
59
????? ???? ?-Display
s
d 1
d 2
d 3
  • ???????? ???????? ???? ????? i ?????? ?? ??????
    ???
  • ?????? ?? ???? ?? d i ?????? ?????? ?????
  • ??????? ?? d i ?????? ?? ????? ?????? ?????
  • ?????? ?????????? ?????? ?? ?????? ?????

q(1, 9)
saved d 2
q(1, 3)
saved d 2
p(1, 3)
saved d 3
e(1, 3)
saved d 2
60
????? ???????
  • ??????? ????????? ??????????.
  • ????? ??????, ??????? ?????????
  • Int ComputePrice(char10 cellphone)
  • ????? ???????, ??????? ?????????
  • price ComputePrice(iPhone 3Gs )
  • Call by value (C, Java ??? ???????, ?????????,
    ???????...)
  • ???? ?? ?????? ?????? ????? (?? ????? ??????) ??
    ????? (?? ?????).
  • ???? ???? ????? ?? ?????? ???????? ?"????"
    ??????? ??????.
  • Call by reference (?????? ?-C ????? ????. ????
    ??????? ??????.)
  • ????? ?????? ?????? ????????.
  • ?? ????? ??????, ?? ???? ????? ????? ?????
    ??????.

61
????? ???????
  • Call by name (Algol 60, ??? ??????? ????)
  • ?? ???? ?? ????? ?????? ???? ????? ????? ??
    ?????? ???????? (??? ????? ?????).
  • Void multiplyConstant (b)
  • global globalb
  • Main ()
  • initiate()
  • multiplyConstant (a5)

62
????? ???????
  • Call by copy-restore (???? aliasing)
  • ?????? ????? ????? ???
  • ?????? ????? ???? ????? ???????.
  • ??????? ????? ?? ?????
  • ????? ??????, ????? ?? ?? ???????? ????? ???? ??
    ?????.
  • Void update (int10 target, int10 source)
  • do (i1 ilt10 i) targeti
    sourcei-1sourcei
  • Main ()
  • initiate()
  • update (A,A)

63
????? ??????? call by value
procedure exchange ( i, j integer ) var x
integer begin x a i a i a
j a j x end
  • ???? ???? ???? ????? ?????

64
????? ??????? call by reference (????? ??????)
  • program reference (input, output)
  • var a, b integer
  • procedure swap ( var x, y integer )
  • var temp integer
  • begin
  • temp x
  • x y
  • y temp
  • end
  • begin
  • a 1 b 2
  • swap (a, b)
  • writeln ( ' a ' , a ) writeln (' b ' , b
    )
  • end .

???? ?????? by reference
65
????? ??????? copy restore
  • ??????? ????? ?? ????? ??????? ?? ?????? ??????
    ??????? ????????

program copyout ( input, output ) var a
integer procedure unsafe (var x integer )
begin x 2 a 0 end begin a 1
unsafe ( a ) writeln ( a ) end.
66
??????
  • ????????? ????? ??? ????? ???? ???? ?????? ???
    ?????? ???? ????? ????.
  • ????? ?????? ??????? ?????????, ????? ??????,
    ????? ????????, ???'.
  • ????? ?????? ???? ?? ???????
  • ????? ?-heap, ????? ??? mark-sweep, copying,
    reference counting.
  • ?????? ??????????
  • Scope ?????? ?????, ?????? ?????? ???????, ?????
    ??????, ???? ??????? ????? ????? ?????? ????
    access link, ???? ?-display. ????? ????? ???????.
Write a Comment
User Comments (0)
About PowerShow.com