home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
browse contents |
view JSON data
|
view as text
This file was processed as: LaTeX Document
(document/latex).
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| LaTeX Document (document/latex)
| magic
| Supported |
1%
| dexvert
| Corel 10 Texture (image/corel10Texture)
| ext
| Unsupported |
1%
| dexvert
| Croteam texture file (image/croteamTextureFile)
| ext
| Unsupported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| C++ source text
| default
| |
99%
| file
| LaTeX document text
| default
| |
98%
| file
| C source text
| default
| |
97%
| file
| C source, ASCII text, with CRLF line terminators
| default
| |
100%
| checkBytes
| Printable ASCII
| default
| |
100%
| perlTextCheck
| Likely Text (Perl)
| default
| |
100%
| siegfried
| fmt/281 LaTeX (Subdocument)
| default
| |
100%
| detectItEasy
| Format: plain text[CRLF]
| default (weak)
|
|
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 63 68 61 70 74 65 72 | 7b 54 68 65 20 4d 61 74 |\chapter|{The Mat|
|00000010| 72 69 78 20 53 74 61 63 | 6b 7d 0d 0a 0d 0a 54 68 |rix Stac|k}....Th|
|00000020| 65 20 6d 61 74 72 69 78 | 20 73 74 61 63 6b 5c 69 |e matrix| stack\i|
|00000030| 6e 64 65 78 7b 4d 53 74 | 61 63 6b 20 7d 20 6c 65 |ndex{MSt|ack } le|
|00000040| 74 73 20 79 6f 75 20 72 | 65 74 75 72 6e 20 56 4d |ts you r|eturn VM|
|00000050| 61 74 72 69 78 0d 0a 72 | 65 66 65 72 65 6e 63 65 |atrix..r|eference|
|00000060| 73 20 66 72 6f 6d 20 6f | 74 68 65 72 20 66 75 6e |s from o|ther fun|
|00000070| 63 74 69 6f 6e 73 2e 20 | 49 74 20 61 6c 73 6f 20 |ctions. |It also |
|00000080| 6b 65 65 70 73 20 74 72 | 61 63 6b 20 6f 66 0d 0a |keeps tr|ack of..|
|00000090| 69 6e 74 65 72 6d 65 64 | 69 61 74 65 20 63 61 6c |intermed|iate cal|
|000000a0| 63 75 61 74 69 6f 6e 73 | 20 73 74 6f 72 65 64 20 |cuations| stored |
|000000b0| 69 6e 20 74 68 65 20 68 | 65 61 70 2c 20 61 6e 64 |in the h|eap, and|
|000000c0| 20 64 65 6c 65 74 65 73 | 20 74 68 65 6d 0d 0a 77 | deletes| them..w|
|000000d0| 68 65 6e 20 6e 65 63 65 | 73 73 61 72 79 2e 20 54 |hen nece|ssary. T|
|000000e0| 68 65 20 63 75 72 72 65 | 6e 74 20 76 65 72 73 69 |he curre|nt versi|
|000000f0| 6f 6e 20 6f 66 20 59 41 | 4d 50 20 75 73 65 73 20 |on of YA|MP uses |
|00000100| 61 20 64 65 65 70 2d 63 | 6f 70 79 0d 0a 74 65 63 |a deep-c|opy..tec|
|00000110| 68 6e 69 71 75 65 20 74 | 6f 20 70 75 73 68 20 6d |hnique t|o push m|
|00000120| 61 74 72 69 63 65 73 20 | 66 61 73 74 65 72 2e 20 |atrices |faster. |
|00000130| 41 73 73 65 6d 62 6c 79 | 20 6c 61 6e 67 75 61 67 |Assembly| languag|
|00000140| 65 20 70 72 6f 67 72 61 | 6d 6d 65 72 73 0d 0a 73 |e progra|mmers..s|
|00000150| 68 6f 75 6c 64 20 61 6c | 72 65 61 64 79 20 62 65 |hould al|ready be|
|00000160| 20 66 61 6d 69 6c 69 61 | 72 20 77 69 74 68 20 74 | familia|r with t|
|00000170| 68 65 20 6d 65 74 68 6f | 64 20 6f 66 20 75 73 69 |he metho|d of usi|
|00000180| 6e 67 20 74 68 65 20 73 | 74 61 63 6b 0d 0a 66 6f |ng the s|tack..fo|
|00000190| 72 20 73 74 6f 72 69 6e | 67 20 72 65 67 69 73 74 |r storin|g regist|
|000001a0| 65 72 73 20 6f 72 20 64 | 61 74 61 20 77 68 65 6e |ers or d|ata when|
|000001b0| 20 6a 75 6d 70 69 6e 67 | 20 74 6f 20 6f 74 68 65 | jumping| to othe|
|000001c0| 72 20 73 65 63 74 69 6f | 6e 73 20 6f 66 0d 0a 63 |r sectio|ns of..c|
|000001d0| 6f 64 65 2e 20 20 54 68 | 65 20 6d 65 74 68 6f 64 |ode. Th|e method|
|000001e0| 20 75 73 65 64 20 68 65 | 72 65 20 69 73 20 6c 69 | used he|re is li|
|000001f0| 74 74 6c 65 20 62 69 74 | 20 73 69 6d 70 6c 65 72 |ttle bit| simpler|
|00000200| 20 74 68 61 6e 20 74 68 | 65 0d 0a 61 73 73 65 6d | than th|e..assem|
|00000210| 62 6c 79 20 73 74 61 63 | 6b 20 6d 65 74 68 6f 64 |bly stac|k method|
|00000220| 73 2e 20 49 74 20 61 6c | 73 6f 20 72 65 71 75 69 |s. It al|so requi|
|00000230| 72 65 73 20 74 68 65 20 | 6c 65 61 73 74 20 61 6d |res the |least am|
|00000240| 6f 75 6e 74 20 6f 66 0d | 0a 64 61 74 61 20 73 74 |ount of.|.data st|
|00000250| 72 75 63 74 75 72 65 20 | 6f 76 65 72 68 65 61 64 |ructure |overhead|
|00000260| 20 74 68 61 74 20 49 20 | 63 6f 75 6c 64 20 63 6f | that I |could co|
|00000270| 6d 65 20 75 70 20 77 69 | 74 68 20 74 6f 20 73 6f |me up wi|th to so|
|00000280| 6c 76 65 20 74 68 65 0d | 0a 70 72 6f 62 6c 65 6d |lve the.|.problem|
|00000290| 20 6f 66 20 74 72 61 70 | 70 69 6e 67 20 61 6c 6c | of trap|ping all|
|000002a0| 6f 63 61 74 69 6f 6e 73 | 20 6f 6e 20 74 68 65 20 |ocations| on the |
|000002b0| 68 65 61 70 2e 20 20 42 | 65 73 69 64 65 73 2c 20 |heap. B|esides, |
|000002c0| 74 6f 20 71 75 6f 74 65 | 0d 0a 4b 6e 75 74 68 5c |to quote|..Knuth\|
|000002d0| 63 69 74 65 7b 4b 6e 3a | 66 61 7d 2c 20 22 41 20 |cite{Kn:|fa}, "A |
|000002e0| 73 74 61 63 6b 20 69 73 | 20 74 68 65 20 73 69 6d |stack is| the sim|
|000002f0| 70 6c 65 73 74 20 6b 69 | 6e 64 20 6f 66 20 6c 69 |plest ki|nd of li|
|00000300| 6e 6b 65 64 0d 0a 6c 69 | 73 74 2e 22 0d 0a 0d 0a |nked..li|st."....|
|00000310| 5c 73 65 63 74 69 6f 6e | 7b 48 6f 77 20 44 6f 65 |\section|{How Doe|
|00000320| 73 20 74 68 65 20 53 74 | 61 63 6b 20 57 6f 72 6b |s the St|ack Work|
|00000330| 3f 7d 0d 0a 54 68 65 20 | 73 74 61 63 6b 20 61 63 |?}..The |stack ac|
|00000340| 63 6f 6d 70 6c 69 73 68 | 65 73 20 74 68 72 65 65 |complish|es three|
|00000350| 20 6f 62 6a 65 63 74 69 | 76 65 73 3a 0d 0a 5c 62 | objecti|ves:..\b|
|00000360| 65 67 69 6e 7b 69 74 65 | 6d 69 7a 65 7d 0d 0a 20 |egin{ite|mize}.. |
|00000370| 20 20 5c 69 74 65 6d 20 | 74 6f 20 6b 65 65 70 20 | \item |to keep |
|00000380| 74 72 61 63 6b 20 6f 66 | 20 69 6e 74 65 72 6d 65 |track of| interme|
|00000390| 64 69 61 74 65 20 6d 61 | 74 72 69 78 20 72 65 66 |diate ma|trix ref|
|000003a0| 65 72 65 6e 63 65 73 20 | 64 75 72 69 6e 67 0d 0a |erences |during..|
|000003b0| 20 20 20 20 20 20 20 20 | 20 6e 65 73 74 65 64 20 | | nested |
|000003c0| 66 75 6e 63 74 69 6f 6e | 20 63 61 6c 6c 73 0d 0a |function| calls..|
|000003d0| 20 20 20 5c 69 74 65 6d | 20 74 6f 20 6b 65 65 70 | \item| to keep|
|000003e0| 20 74 72 61 63 6b 20 6f | 66 20 74 68 65 20 6c 65 | track o|f the le|
|000003f0| 76 65 6c 20 6f 66 20 6e | 65 73 74 69 6e 67 20 69 |vel of n|esting i|
|00000400| 6e 20 74 68 65 0d 0a 20 | 20 20 20 20 20 20 20 20 |n the.. | |
|00000410| 6e 65 73 74 65 64 20 66 | 75 6e 63 74 69 6f 6e 20 |nested f|unction |
|00000420| 63 61 6c 6c 73 2e 0d 0a | 20 20 20 5c 69 74 65 6d |calls...| \item|
|00000430| 20 65 78 70 6c 69 63 69 | 74 20 63 6f 6e 74 72 6f | explici|t contro|
|00000440| 6c 20 6f 66 20 67 61 72 | 62 61 67 65 20 63 6f 6c |l of gar|bage col|
|00000450| 6c 65 63 74 69 6f 6e 20 | 66 6f 72 20 74 65 6d 70 |lection |for temp|
|00000460| 6f 72 61 72 79 0d 0a 20 | 20 20 20 20 20 20 20 20 |orary.. | |
|00000470| 6d 61 74 72 69 63 65 73 | 2e 0d 0a 5c 65 6e 64 7b |matrices|...\end{|
|00000480| 69 74 65 6d 69 7a 65 7d | 0d 0a 43 6f 6e 73 69 64 |itemize}|..Consid|
|00000490| 65 72 20 74 68 65 20 70 | 72 6f 62 6c 65 6d 73 20 |er the p|roblems |
|000004a0| 61 73 73 6f 63 69 61 74 | 65 64 20 77 69 74 68 20 |associat|ed with |
|000004b0| 74 68 65 20 66 6f 6c 6c | 6f 77 69 6e 67 20 63 6f |the foll|owing co|
|000004c0| 64 65 0d 0a 5c 62 65 67 | 69 6e 7b 76 65 72 62 61 |de..\beg|in{verba|
|000004d0| 74 69 6d 7d 0d 0a 20 20 | 20 56 4d 61 74 72 69 78 |tim}.. | VMatrix|
|000004e0| 20 26 66 31 28 20 76 6f | 69 64 20 29 0d 0a 20 20 | &f1( vo|id ).. |
|000004f0| 20 20 20 7b 0d 0a 20 20 | 20 20 20 20 20 56 4d 61 | {.. | VMa|
|00000500| 74 72 69 78 20 62 28 22 | 6c 6f 63 61 6c 20 6d 61 |trix b("|local ma|
|00000510| 74 22 2c 35 2c 35 29 3b | 0d 0a 20 20 20 20 20 20 |t",5,5);|.. |
|00000520| 20 72 65 74 75 72 6e 20 | 62 3b 0d 0a 20 20 20 20 | return |b;.. |
|00000530| 20 7d 0d 0a 20 20 20 56 | 4d 61 74 72 69 78 20 26 | }.. V|Matrix &|
|00000540| 66 32 28 20 76 6f 69 64 | 20 29 0d 0a 20 20 20 20 |f2( void| ).. |
|00000550| 20 7b 0d 0a 20 20 20 20 | 20 20 20 20 56 4d 61 74 | {.. | VMat|
|00000560| 72 69 78 20 2a 62 20 3d | 20 6e 65 77 20 56 4d 61 |rix *b =| new VMa|
|00000570| 74 72 69 78 28 22 6c 6f | 63 61 6c 20 6d 61 74 22 |trix("lo|cal mat"|
|00000580| 2c 35 2c 35 29 3b 0d 0a | 20 20 20 20 20 20 20 20 |,5,5);..| |
|00000590| 72 65 74 75 72 6e 20 2a | 62 3b 0d 0a 20 20 20 20 |return *|b;.. |
|000005a0| 20 7d 0d 0a 20 20 20 6d | 61 69 6e 28 29 0d 0a 20 | }.. m|ain().. |
|000005b0| 20 20 20 20 7b 0d 0a 20 | 20 20 20 20 20 20 20 56 | {.. | V|
|000005c0| 4d 61 74 72 69 78 20 63 | 3b 0d 0a 20 20 20 20 20 |Matrix c|;.. |
|000005d0| 20 20 0d 0a 20 20 20 20 | 20 20 20 20 63 3d 20 66 | .. | c= f|
|000005e0| 31 28 29 20 2b 20 66 32 | 28 29 3b 0d 0a 20 20 20 |1() + f2|();.. |
|000005f0| 20 20 7d 0d 0a 5c 65 6e | 64 7b 76 65 72 62 61 74 | }..\en|d{verbat|
|00000600| 69 6d 7d 0d 0a 54 68 69 | 73 20 63 6f 64 65 20 77 |im}..Thi|s code w|
|00000610| 6f 6e 27 74 20 77 6f 72 | 6b 2e 20 54 68 65 20 63 |on't wor|k. The c|
|00000620| 61 6c 6c 20 74 6f 20 66 | 31 28 29 20 61 74 74 65 |all to f|1() atte|
|00000630| 6d 70 74 73 20 74 6f 20 | 72 65 74 75 72 6e 20 61 |mpts to |return a|
|00000640| 0d 0a 6c 6f 63 61 6c 20 | 6d 61 74 72 69 78 2e 20 |..local |matrix. |
|00000650| 48 6f 77 65 76 65 72 2c | 20 43 2b 2b 20 63 61 6c |However,| C++ cal|
|00000660| 6c 73 20 74 68 65 20 64 | 65 73 74 72 75 63 74 6f |ls the d|estructo|
|00000670| 72 20 6f 66 20 62 20 62 | 65 66 6f 72 65 0d 0a 72 |r of b b|efore..r|
|00000680| 65 74 75 72 6e 69 6e 67 | 2c 20 73 6f 20 74 68 65 |eturning|, so the|
|00000690| 20 72 65 74 75 72 6e 65 | 64 20 72 65 66 65 72 65 | returne|d refere|
|000006a0| 6e 63 65 20 70 6f 69 6e | 74 73 20 74 6f 20 61 6e |nce poin|ts to an|
|000006b0| 0d 0a 61 62 61 6e 64 6f | 6e 64 65 64 20 6c 6f 63 |..abando|nded loc|
|000006c0| 61 74 69 6f 6e 20 69 6e | 20 74 68 65 20 70 72 6f |ation in| the pro|
|000006d0| 67 72 61 6d 20 73 74 61 | 63 6b 2c 20 61 6e 64 20 |gram sta|ck, and |
|000006e0| 68 65 6e 63 65 20 74 6f | 0d 0a 67 61 72 62 61 67 |hence to|..garbag|
|000006f0| 65 2e 20 54 68 65 20 63 | 61 6c 6c 20 74 6f 20 66 |e. The c|all to f|
|00000700| 32 28 29 20 64 6f 65 73 | 20 6e 6f 74 20 71 75 69 |2() does| not qui|
|00000710| 74 65 20 73 6f 6c 76 65 | 20 74 68 65 20 70 72 6f |te solve| the pro|
|00000720| 62 6c 65 6d 20 6f 66 0d | 0a 66 31 28 29 2e 20 49 |blem of.|.f1(). I|
|00000730| 74 20 72 65 74 75 72 6e | 73 20 61 20 76 61 6c 69 |t return|s a vali|
|00000740| 64 20 72 65 66 65 72 65 | 6e 63 65 20 74 6f 20 61 |d refere|nce to a|
|00000750| 20 6d 61 74 72 69 78 2c | 20 62 75 74 20 74 68 65 | matrix,| but the|
|00000760| 0d 0a 72 65 66 65 72 65 | 6e 63 65 20 69 73 20 6c |..refere|nce is l|
|00000770| 6f 73 74 20 6f 6e 63 65 | 20 74 68 65 20 65 71 75 |ost once| the equ|
|00000780| 61 6c 20 73 69 67 6e 20 | 69 73 20 70 72 6f 63 65 |al sign |is proce|
|00000790| 73 73 65 64 20 69 6e 20 | 74 68 65 0d 0a 6d 61 69 |ssed in |the..mai|
|000007a0| 6e 20 66 75 6e 63 74 69 | 6f 6e 2e 20 49 74 20 69 |n functi|on. It i|
|000007b0| 73 20 6c 6f 73 74 20 69 | 6e 20 74 68 65 20 73 65 |s lost i|n the se|
|000007c0| 6e 73 65 20 74 68 61 74 | 20 6e 6f 20 76 61 72 69 |nse that| no vari|
|000007d0| 61 62 6c 65 0d 0a 63 6f | 6e 74 61 69 6e 73 20 74 |able..co|ntains t|
|000007e0| 68 65 20 72 65 66 65 72 | 65 6e 63 65 2c 20 73 6f |he refer|ence, so|
|000007f0| 20 69 74 20 63 61 6e 6e | 6f 74 20 62 65 20 72 65 | it cann|ot be re|
|00000800| 6d 6f 76 65 64 20 66 72 | 6f 6d 20 74 68 65 0d 0a |moved fr|om the..|
|00000810| 68 65 61 70 2e 20 49 66 | 20 79 6f 75 20 63 61 6c |heap. If| you cal|
|00000820| 6c 20 66 32 28 29 20 74 | 6f 6f 20 6f 66 74 65 6e |l f2() t|oo often|
|00000830| 2c 20 74 68 65 20 68 65 | 61 70 20 77 69 6c 6c 20 |, the he|ap will |
|00000840| 66 69 6c 6c 20 75 70 20 | 61 6e 64 0d 0a 74 68 65 |fill up |and..the|
|00000850| 20 70 72 6f 67 72 61 6d | 20 77 69 6c 6c 20 63 72 | program| will cr|
|00000860| 61 73 68 2e 20 42 6f 74 | 68 20 6f 66 20 74 68 65 |ash. Bot|h of the|
|00000870| 73 65 20 70 72 6f 62 6c | 65 6d 73 20 61 72 65 20 |se probl|ems are |
|00000880| 73 6f 6c 76 65 64 0d 0a | 62 79 20 74 68 65 20 73 |solved..|by the s|
|00000890| 74 61 63 6b 2e 20 54 68 | 65 20 73 6f 6c 75 74 69 |tack. Th|e soluti|
|000008a0| 6f 6e 20 69 73 20 74 6f | 20 73 74 6f 72 65 20 61 |on is to| store a|
|000008b0| 20 63 6f 70 79 20 6f 66 | 20 74 68 65 20 6d 61 74 | copy of| the mat|
|000008c0| 72 69 78 0d 0a 69 6e 20 | 74 68 65 20 73 74 61 63 |rix..in |the stac|
|000008d0| 6b 2c 20 77 68 69 63 68 | 20 69 73 20 61 20 67 6c |k, which| is a gl|
|000008e0| 6f 62 61 6c 20 64 61 74 | 61 20 73 74 72 75 63 74 |obal dat|a struct|
|000008f0| 75 72 65 2e 20 54 68 65 | 20 63 6f 72 72 65 63 74 |ure. The| correct|
|00000900| 0d 0a 70 72 6f 67 72 61 | 6d 20 61 62 6f 76 65 20 |..progra|m above |
|00000910| 74 68 65 6e 20 69 73 20 | 0d 0a 5c 62 65 67 69 6e |then is |..\begin|
|00000920| 7b 76 65 72 62 61 74 69 | 6d 7d 0d 0a 20 20 20 23 |{verbati|m}.. #|
|00000930| 69 6e 63 6c 75 64 65 20 | 22 76 69 72 74 2e 68 22 |include |"virt.h"|
|00000940| 0d 0a 20 20 20 4d 53 74 | 61 63 6b 20 2a 44 69 73 |.. MSt|ack *Dis|
|00000950| 70 61 74 63 68 20 3d 20 | 6e 65 77 20 4d 53 74 61 |patch = |new MSta|
|00000960| 63 6b 3b 0d 0a 0d 0a 20 | 20 20 56 4d 61 74 72 69 |ck;.... | VMatri|
|00000970| 78 20 26 66 31 28 20 76 | 6f 69 64 20 29 0d 0a 20 |x &f1( v|oid ).. |
|00000980| 20 20 20 20 7b 0d 0a 20 | 20 20 20 20 20 56 4d 61 | {.. | VMa|
|00000990| 74 72 69 78 20 62 28 22 | 6c 6f 63 61 6c 20 6d 61 |trix b("|local ma|
|000009a0| 74 22 2c 35 2c 35 29 3b | 0d 0a 20 20 20 20 20 20 |t",5,5);|.. |
|000009b0| 44 69 73 70 61 74 63 68 | 2d 3e 50 75 73 68 28 62 |Dispatch|->Push(b|
|000009c0| 29 3b 20 0d 0a 20 20 20 | 20 20 20 72 65 74 75 72 |); .. | retur|
|000009d0| 6e 20 44 69 73 70 61 74 | 63 68 2d 3e 52 65 74 75 |n Dispat|ch->Retu|
|000009e0| 72 6e 4d 61 74 28 29 3b | 0d 0a 20 20 20 20 20 7d |rnMat();|.. }|
|000009f0| 0d 0a 20 20 20 56 4d 61 | 74 72 69 78 20 26 66 32 |.. VMa|trix &f2|
|00000a00| 28 20 76 6f 69 64 20 29 | 0d 0a 20 20 20 20 20 7b |( void )|.. {|
|00000a10| 0d 0a 20 20 20 20 20 20 | 20 20 56 4d 61 74 72 69 |.. | VMatri|
|00000a20| 78 20 2a 62 20 3d 20 6e | 65 77 20 56 4d 61 74 72 |x *b = n|ew VMatr|
|00000a30| 69 78 28 22 6c 6f 63 61 | 6c 20 6d 61 74 22 2c 35 |ix("loca|l mat",5|
|00000a40| 2c 35 29 3b 0d 0a 20 20 | 20 20 20 20 20 20 44 69 |,5);.. | Di|
|00000a50| 73 70 61 74 63 68 2d 3e | 50 75 73 68 28 2a 62 29 |spatch->|Push(*b)|
|00000a60| 3b 0d 0a 20 20 20 20 20 | 20 20 20 64 65 6c 65 74 |;.. | delet|
|00000a70| 65 20 62 3b 0d 0a 20 20 | 20 20 20 20 20 20 72 65 |e b;.. | re|
|00000a80| 74 75 72 6e 20 44 69 73 | 70 61 74 63 68 2d 3e 52 |turn Dis|patch->R|
|00000a90| 65 74 75 72 6e 4d 61 74 | 28 29 3b 0d 0a 20 20 20 |eturnMat|();.. |
|00000aa0| 20 20 7d 0d 0a 20 20 20 | 6d 61 69 6e 28 29 0d 0a | }.. |main()..|
|00000ab0| 20 20 20 20 20 7b 0d 0a | 20 20 20 20 20 20 20 20 | {..| |
|00000ac0| 56 4d 61 74 72 69 78 20 | 63 3b 0d 0a 20 20 20 20 |VMatrix |c;.. |
|00000ad0| 20 20 20 20 63 3d 20 66 | 31 28 29 20 2b 20 66 32 | c= f|1() + f2|
|00000ae0| 28 29 3b 0d 0a 20 20 20 | 20 20 20 20 20 76 63 6c |();.. | vcl|
|00000af0| 6f 73 65 28 29 3b 0d 0a | 20 20 20 20 20 7d 0d 0a |ose();..| }..|
|00000b00| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 0d 0a |\end{ver|batim}..|
|00000b10| 54 68 69 73 20 70 72 6f | 67 72 61 6d 20 77 69 6c |This pro|gram wil|
|00000b20| 6c 20 77 6f 72 6b 20 61 | 73 20 6c 6f 6e 67 20 61 |l work a|s long a|
|00000b30| 73 20 79 6f 75 20 64 6f | 20 6e 6f 74 20 6e 65 65 |s you do| not nee|
|00000b40| 64 20 74 6f 0d 0a 63 6f | 6e 74 72 6f 6c 20 74 68 |d to..co|ntrol th|
|00000b50| 65 20 66 75 6e 63 74 69 | 6f 6e 20 6e 65 73 74 69 |e functi|on nesti|
|00000b60| 6e 67 20 6c 65 76 65 6c | 2e 20 54 68 65 20 6e 65 |ng level|. The ne|
|00000b70| 78 74 20 65 78 61 6d 70 | 6c 65 20 73 68 6f 77 73 |xt examp|le shows|
|00000b80| 0d 0a 68 6f 77 20 79 6f | 75 20 63 61 6e 20 75 73 |..how yo|u can us|
|00000b90| 65 20 74 68 65 20 66 75 | 6e 63 74 69 6f 6e 20 6e |e the fu|nction n|
|00000ba0| 65 73 74 69 6e 67 20 6c | 65 76 65 6c 20 74 6f 20 |esting l|evel to |
|00000bb0| 75 73 65 20 6d 61 74 72 | 69 78 0d 0a 61 73 73 69 |use matr|ix..assi|
|00000bc0| 67 6e 6d 65 6e 74 20 69 | 6e 20 61 6c 6c 20 66 75 |gnment i|n all fu|
|00000bd0| 6e 63 74 69 6f 6e 73 2e | 0d 0a 5c 62 65 67 69 6e |nctions.|..\begin|
|00000be0| 7b 76 65 72 62 61 74 69 | 6d 7d 0d 0a 20 20 20 23 |{verbati|m}.. #|
|00000bf0| 69 6e 63 6c 75 64 65 20 | 22 76 69 72 74 2e 68 22 |include |"virt.h"|
|00000c00| 0d 0a 20 20 20 4d 53 74 | 61 63 6b 20 2a 44 69 73 |.. MSt|ack *Dis|
|00000c10| 70 61 74 63 68 20 3d 20 | 6e 65 77 20 4d 53 74 61 |patch = |new MSta|
|00000c20| 63 6b 3b 0d 0a 0d 0a 20 | 20 20 56 4d 61 74 72 69 |ck;.... | VMatri|
|00000c30| 78 20 26 66 31 28 20 76 | 6f 69 64 20 29 0d 0a 20 |x &f1( v|oid ).. |
|00000c40| 20 20 20 20 7b 0d 0a 20 | 20 20 20 20 20 56 4d 61 | {.. | VMa|
|00000c50| 74 72 69 78 20 62 20 3d | 20 46 69 6c 6c 28 35 2c |trix b =| Fill(5,|
|00000c60| 35 2c 31 29 3b 0d 0a 20 | 20 20 20 20 20 62 2e 4e |5,1);.. | b.N|
|00000c70| 61 6d 65 69 74 28 22 4c | 6f 63 61 6c 22 29 3b 0d |ameit("L|ocal");.|
|00000c80| 0a 20 20 20 20 20 20 44 | 69 73 70 61 74 63 68 2d |. D|ispatch-|
|00000c90| 3e 50 75 73 68 28 62 29 | 3b 20 0d 0a 20 20 20 20 |>Push(b)|; .. |
|00000ca0| 20 20 72 65 74 75 72 6e | 20 44 69 73 70 61 74 63 | return| Dispatc|
|00000cb0| 68 2d 3e 52 65 74 75 72 | 6e 4d 61 74 28 29 3b 0d |h->Retur|nMat();.|
|00000cc0| 0a 20 20 20 20 20 7d 0d | 0a 20 20 20 56 4d 61 74 |. }.|. VMat|
|00000cd0| 72 69 78 20 26 66 32 28 | 20 76 6f 69 64 20 29 0d |rix &f2(| void ).|
|00000ce0| 0a 20 20 20 20 20 7b 0d | 0a 20 20 20 20 20 20 20 |. {.|. |
|00000cf0| 20 44 69 73 70 61 74 63 | 68 2d 3e 49 6e 63 6c 65 | Dispatc|h->Incle|
|00000d00| 76 65 6c 28 29 0d 0a 20 | 20 20 20 20 20 20 20 56 |vel().. | V|
|00000d10| 4d 61 74 72 69 78 20 2a | 62 20 3d 20 6e 65 77 20 |Matrix *|b = new |
|00000d20| 56 4d 61 74 72 69 78 3b | 0d 0a 20 20 20 20 20 20 |VMatrix;|.. |
|00000d30| 20 20 2a 62 20 3d 20 46 | 69 6c 6c 28 35 2c 35 2c | *b = F|ill(5,5,|
|00000d40| 32 29 3b 0d 0a 20 20 20 | 20 20 20 20 20 62 2d 3e |2);.. | b->|
|00000d50| 4e 61 6d 65 69 74 28 22 | 70 6f 69 6e 74 65 72 22 |Nameit("|pointer"|
|00000d60| 29 3b 0d 0a 20 20 20 20 | 20 20 20 20 44 69 73 70 |);.. | Disp|
|00000d70| 61 74 63 68 2d 3e 50 75 | 73 68 28 2a 62 29 3b 0d |atch->Pu|sh(*b);.|
|00000d80| 0a 20 20 20 20 20 20 20 | 20 64 65 6c 65 74 65 20 |. | delete |
|00000d90| 62 3b 0d 0a 20 20 20 20 | 20 20 20 20 72 65 74 75 |b;.. | retu|
|00000da0| 72 6e 20 44 69 73 70 61 | 74 63 68 2d 3e 44 65 63 |rn Dispa|tch->Dec|
|00000db0| 72 65 74 75 72 6e 28 29 | 3b 0d 0a 20 20 20 20 20 |return()|;.. |
|00000dc0| 7d 0d 0a 20 20 20 56 4d | 61 74 72 69 78 20 26 66 |}.. VM|atrix &f|
|00000dd0| 33 28 20 76 6f 69 64 20 | 29 0d 0a 20 20 20 20 20 |3( void |).. |
|00000de0| 7b 0d 0a 20 20 20 20 20 | 20 20 20 20 44 69 73 70 |{.. | Disp|
|00000df0| 61 74 63 68 2d 3e 49 6e | 63 6c 65 76 65 6c 28 29 |atch->In|clevel()|
|00000e00| 3b 0d 0a 20 20 20 20 20 | 20 20 20 20 56 4d 61 74 |;.. | VMat|
|00000e10| 72 69 78 20 62 20 20 3d | 20 66 31 28 29 20 2b 20 |rix b =| f1() + |
|00000e20| 66 32 28 29 3b 0d 0a 20 | 20 20 20 20 20 20 20 20 |f2();.. | |
|00000e30| 44 69 73 70 61 74 63 68 | 2d 3e 50 75 73 68 28 62 |Dispatch|->Push(b|
|00000e40| 29 3b 0d 0a 20 20 20 20 | 20 20 20 20 20 72 65 74 |);.. | ret|
|00000e50| 75 72 6e 20 44 69 73 70 | 61 74 63 68 2d 3e 44 65 |urn Disp|atch->De|
|00000e60| 63 52 65 74 75 72 6e 28 | 29 3b 0d 0a 20 20 20 20 |cReturn(|);.. |
|00000e70| 20 20 7d 0d 0a 20 20 20 | 6d 61 69 6e 28 29 0d 0a | }.. |main()..|
|00000e80| 20 20 20 20 20 7b 0d 0a | 20 20 20 20 20 20 20 20 | {..| |
|00000e90| 56 4d 61 74 72 69 78 20 | 63 20 3d 20 66 31 28 29 |VMatrix |c = f1()|
|00000ea0| 20 2b 20 66 33 28 29 20 | 2b 20 66 32 28 29 3b 0d | + f3() |+ f2();.|
|00000eb0| 0a 20 20 20 20 20 20 20 | 20 76 63 6c 6f 73 65 28 |. | vclose(|
|00000ec0| 29 3b 0d 0a 20 20 20 20 | 20 7d 0d 0a 5c 65 6e 64 |);.. | }..\end|
|00000ed0| 7b 76 65 72 62 61 74 69 | 6d 7d 0d 0a 4e 6f 74 65 |{verbati|m}..Note|
|00000ee0| 20 74 68 61 74 20 61 20 | 6d 61 74 72 69 78 20 61 | that a |matrix a|
|00000ef0| 73 73 69 67 6e 6d 65 6e | 74 20 69 73 20 75 73 65 |ssignmen|t is use|
|00000f00| 64 20 69 6e 20 66 33 28 | 29 2e 20 54 68 65 20 73 |d in f3(|). The s|
|00000f10| 74 61 63 6b 20 69 73 0d | 0a 63 6c 65 61 72 65 64 |tack is.|.cleared|
|00000f20| 20 6f 66 20 69 6e 74 65 | 72 6d 65 64 69 61 74 65 | of inte|rmediate|
|00000f30| 20 6d 61 74 72 69 63 65 | 73 20 77 68 65 6e 20 75 | matrice|s when u|
|00000f40| 73 69 6e 67 20 6d 61 74 | 72 69 78 0d 0a 61 73 73 |sing mat|rix..ass|
|00000f50| 69 67 6e 6d 65 6e 74 20 | 62 79 20 63 61 6c 6c 69 |ignment |by calli|
|00000f60| 6e 67 20 43 6c 65 61 6e | 53 74 61 63 6b 28 29 2e |ng Clean|Stack().|
|00000f70| 20 54 68 65 20 6d 61 74 | 72 69 78 20 6e 65 73 74 | The mat|rix nest|
|00000f80| 69 6e 67 20 6c 65 76 65 | 6c 0d 0a 69 6e 64 65 78 |ing leve|l..index|
|00000f90| 20 69 73 20 75 73 65 64 | 20 74 6f 20 64 65 74 65 | is used| to dete|
|00000fa0| 72 6d 69 6e 65 20 77 68 | 69 63 68 20 6d 61 74 72 |rmine wh|ich matr|
|00000fb0| 69 63 65 73 20 61 72 65 | 20 74 6f 20 62 65 20 72 |ices are| to be r|
|00000fc0| 65 6d 6f 76 65 64 0d 0a | 66 72 6f 6d 20 74 68 65 |emoved..|from the|
|00000fd0| 20 73 74 61 63 6b 2e 20 | 57 68 65 6e 20 66 33 28 | stack. |When f3(|
|00000fe0| 29 20 69 73 20 63 61 6c | 6c 65 64 2c 20 66 32 28 |) is cal|led, f2(|
|00000ff0| 29 20 68 61 73 20 61 6c | 72 65 61 64 79 20 62 65 |) has al|ready be|
|00001000| 65 6e 0d 0a 63 61 6c 6c | 65 64 20 69 6e 20 6d 61 |en..call|ed in ma|
|00001010| 69 6e 28 29 2c 20 73 6f | 20 74 68 65 20 73 74 61 |in(), so| the sta|
|00001020| 63 6b 20 68 61 73 20 74 | 68 65 20 72 65 73 75 6c |ck has t|he resul|
|00001030| 74 20 6f 66 20 66 32 28 | 29 20 69 6e 0d 0a 69 74 |t of f2(|) in..it|
|00001040| 2e 20 54 68 69 73 20 63 | 6f 70 79 20 77 69 6c 6c |. This c|opy will|
|00001050| 20 6e 6f 74 20 62 65 20 | 65 72 61 73 65 64 20 77 | not be |erased w|
|00001060| 68 65 6e 20 66 33 28 29 | 20 63 61 6c 6c 73 20 74 |hen f3()| calls t|
|00001070| 68 65 20 65 71 75 61 6c | 73 0d 0a 6f 70 65 72 61 |he equal|s..opera|
|00001080| 74 6f 72 20 62 65 63 61 | 75 73 65 20 74 68 65 20 |tor beca|use the |
|00001090| 6e 65 73 74 69 6e 67 20 | 6c 65 76 65 6c 20 69 73 |nesting |level is|
|000010a0| 20 69 6e 63 72 65 6d 65 | 6e 74 65 64 20 61 74 20 | increme|nted at |
|000010b0| 74 68 65 0d 0a 66 75 6e | 63 74 69 6f 6e 20 65 6e |the..fun|ction en|
|000010c0| 74 72 79 2e 20 4f 6e 6c | 79 20 74 68 65 20 72 65 |try. Onl|y the re|
|000010d0| 73 75 6c 74 73 20 6f 6e | 20 74 68 65 20 73 74 61 |sults on| the sta|
|000010e0| 63 6b 20 63 72 65 61 74 | 65 64 20 77 68 69 6c 65 |ck creat|ed while|
|000010f0| 0d 0a 66 33 28 29 20 69 | 73 20 61 63 74 69 76 65 |..f3() i|s active|
|00001100| 20 61 72 65 20 70 6f 70 | 70 65 64 20 6f 66 66 20 | are pop|ped off |
|00001110| 74 68 65 20 73 74 61 63 | 6b 2e 20 54 68 75 73 20 |the stac|k. Thus |
|00001120| 74 68 65 20 66 69 72 73 | 74 20 63 6f 70 79 0d 0a |the firs|t copy..|
|00001130| 6f 66 20 66 32 28 29 20 | 69 6e 20 6d 61 69 6e 28 |of f2() |in main(|
|00001140| 29 20 61 72 65 20 70 72 | 65 73 65 72 76 65 64 2e |) are pr|eserved.|
|00001150| 20 0d 0a 0d 0a 54 68 65 | 20 64 69 66 66 65 72 65 | ....The| differe|
|00001160| 6e 63 65 20 62 65 74 77 | 65 65 6e 20 44 69 73 70 |nce betw|een Disp|
|00001170| 61 74 63 68 2d 24 3e 24 | 52 65 74 75 72 6e 4d 61 |atch-$>$|ReturnMa|
|00001180| 74 28 29 20 61 6e 64 0d | 0a 44 69 73 70 61 74 63 |t() and.|.Dispatc|
|00001190| 68 2d 24 3e 24 44 65 63 | 52 65 74 75 72 6e 28 29 |h-$>$Dec|Return()|
|000011a0| 20 69 73 20 74 68 61 74 | 20 44 65 63 52 65 74 75 | is that| DecRetu|
|000011b0| 72 6e 20 64 65 63 72 65 | 6d 65 6e 74 73 20 74 68 |rn decre|ments th|
|000011c0| 65 20 6d 61 74 72 69 78 | 0d 0a 6e 65 73 74 69 6e |e matrix|..nestin|
|000011d0| 67 20 6c 65 76 65 6c 20 | 61 6e 64 20 52 65 74 75 |g level |and Retu|
|000011e0| 72 6e 4d 61 74 28 29 20 | 64 6f 65 73 20 6e 6f 74 |rnMat() |does not|
|000011f0| 2e 20 59 6f 75 20 75 73 | 65 20 52 65 74 75 72 6e |. You us|e Return|
|00001200| 4d 61 74 28 29 20 69 66 | 0d 0a 79 6f 75 20 64 69 |Mat() if|..you di|
|00001210| 64 20 6e 6f 74 20 6e 65 | 65 64 20 6d 61 74 72 69 |d not ne|ed matri|
|00001220| 78 20 61 73 73 69 67 6e | 6d 65 6e 74 20 69 6e 20 |x assign|ment in |
|00001230| 61 20 66 75 6e 63 74 69 | 6f 6e 2c 20 61 6e 64 20 |a functi|on, and |
|00001240| 68 65 6e 63 65 20 64 69 | 64 0d 0a 6e 6f 74 20 63 |hence di|d..not c|
|00001250| 61 6c 6c 20 49 6e 63 6c | 65 76 65 6c 28 29 20 61 |all Incl|evel() a|
|00001260| 74 20 74 68 65 20 74 6f | 70 2e 20 59 6f 75 20 75 |t the to|p. You u|
|00001270| 73 65 20 44 65 63 52 65 | 74 75 72 6e 28 29 20 69 |se DecRe|turn() i|
|00001280| 66 20 79 6f 75 0d 0a 6e | 65 65 64 65 64 20 74 6f |f you..n|eeded to|
|00001290| 20 75 73 65 20 6d 61 74 | 72 69 78 20 61 73 73 69 | use mat|rix assi|
|000012a0| 67 6e 6d 65 6e 74 20 68 | 65 6e 63 65 20 63 61 6c |gnment h|ence cal|
|000012b0| 6c 65 64 20 49 6e 63 6c | 65 76 65 6c 28 29 20 61 |led Incl|evel() a|
|000012c0| 74 20 74 68 65 0d 0a 74 | 6f 70 2e 20 0d 0a 0d 0a |t the..t|op. ....|
|000012d0| 49 20 63 68 6f 73 65 20 | 74 68 65 20 77 6f 72 64 |I chose |the word|
|000012e0| 20 44 69 73 70 61 74 63 | 68 20 66 6f 72 20 74 68 | Dispatc|h for th|
|000012f0| 65 20 73 74 61 63 6b 20 | 72 6f 6f 74 20 74 6f 20 |e stack |root to |
|00001300| 73 75 67 67 65 73 74 0d | 0a 74 68 61 74 20 22 6d |suggest.|.that "m|
|00001310| 65 73 73 61 67 65 73 22 | 20 6d 61 79 20 62 65 20 |essages"| may be |
|00001320| 73 65 6e 74 20 74 6f 20 | 74 68 65 20 73 74 61 63 |sent to |the stac|
|00001330| 6b 20 74 68 72 6f 75 67 | 68 20 74 68 65 20 73 74 |k throug|h the st|
|00001340| 61 63 6b 0d 0a 64 69 73 | 70 61 74 63 68 65 72 2e |ack..dis|patcher.|
|00001350| 20 20 54 68 65 20 73 74 | 61 63 6b 20 73 68 6f 75 | The st|ack shou|
|00001360| 6c 64 20 62 65 20 64 65 | 63 6c 61 72 65 64 20 69 |ld be de|clared i|
|00001370| 6e 20 74 68 65 20 67 6c | 6f 62 61 6c 20 64 61 74 |n the gl|obal dat|
|00001380| 61 0d 0a 61 72 65 61 20 | 61 73 20 61 20 70 6f 69 |a..area |as a poi|
|00001390| 6e 74 65 72 2e 20 54 68 | 69 73 20 69 73 20 65 78 |nter. Th|is is ex|
|000013a0| 70 65 63 74 65 64 20 74 | 68 72 6f 75 67 68 6f 75 |pected t|hroughou|
|000013b0| 74 20 74 68 65 20 70 72 | 6f 67 72 61 6d 2e 20 20 |t the pr|ogram. |
|000013c0| 0d 0a 0d 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |....\sub|section{|
|000013d0| 47 61 72 62 61 67 65 20 | 43 6f 6c 6c 65 63 74 69 |Garbage |Collecti|
|000013e0| 6f 6e 20 75 73 69 6e 67 | 20 74 68 65 20 53 74 61 |on using| the Sta|
|000013f0| 63 6b 7d 0d 0a 53 6f 6d | 65 20 61 75 74 68 6f 72 |ck}..Som|e author|
|00001400| 73 20 61 72 67 75 65 20 | 74 68 61 74 20 61 6e 20 |s argue |that an |
|00001410| 65 78 70 6c 69 63 69 74 | 20 73 74 61 63 6b 20 69 |explicit| stack i|
|00001420| 73 20 6e 6f 74 20 6e 65 | 63 65 73 73 61 72 79 2c |s not ne|cessary,|
|00001430| 20 61 6e 64 0d 0a 69 73 | 20 69 6e 64 65 65 64 20 | and..is| indeed |
|00001440| 74 68 65 20 72 65 73 70 | 6f 6e 73 69 62 6c 69 74 |the resp|onsiblit|
|00001450| 79 20 6f 66 20 74 68 65 | 20 63 6f 6d 70 69 6c 65 |y of the| compile|
|00001460| 72 20 28 53 65 65 20 45 | 63 6b 65 6c 0d 0a 5c 63 |r (See E|ckel..\c|
|00001470| 69 74 65 7b 45 4b 3a 55 | 43 7d 29 2e 20 54 68 65 |ite{EK:U|C}). The|
|00001480| 20 70 72 6f 62 6c 65 6d | 20 77 69 74 68 20 74 68 | problem| with th|
|00001490| 69 73 20 61 70 70 72 6f | 61 63 68 20 69 73 20 74 |is appro|ach is t|
|000014a0| 68 61 74 20 75 73 69 6e | 67 20 74 68 65 0d 0a 70 |hat usin|g the..p|
|000014b0| 72 6f 67 72 61 6d 20 73 | 74 61 63 6b 20 74 6f 20 |rogram s|tack to |
|000014c0| 6b 65 65 70 20 74 72 61 | 63 6b 20 6f 66 20 74 68 |keep tra|ck of th|
|000014d0| 65 20 74 65 6d 70 6f 72 | 61 72 79 20 6d 61 74 72 |e tempor|ary matr|
|000014e0| 69 63 65 73 20 61 6c 6c | 6f 77 73 20 74 68 65 0d |ices all|ows the.|
|000014f0| 0a 74 65 6d 70 6f 72 61 | 72 79 20 6d 61 74 72 69 |.tempora|ry matri|
|00001500| 63 65 73 20 74 6f 20 73 | 74 61 79 20 6f 6e 20 74 |ces to s|tay on t|
|00001510| 68 65 20 73 74 61 63 6b | 20 75 6e 74 69 6c 20 74 |he stack| until t|
|00001520| 68 65 79 20 67 6f 20 6f | 75 74 20 6f 66 0d 0a 73 |hey go o|ut of..s|
|00001530| 63 6f 70 65 2e 20 54 68 | 65 79 20 68 61 6e 67 20 |cope. Th|ey hang |
|00001540| 61 72 6f 75 6e 64 20 61 | 6e 64 20 63 61 75 73 65 |around a|nd cause|
|00001550| 20 73 74 61 63 6b 20 6f | 76 65 72 66 6c 6f 77 73 | stack o|verflows|
|00001560| 20 69 6e 20 6c 61 72 67 | 65 0d 0a 73 75 62 72 6f | in larg|e..subro|
|00001570| 75 74 69 6e 65 73 2e 20 | 54 68 69 73 20 68 61 70 |utines. |This hap|
|00001580| 70 65 6e 73 20 65 76 65 | 6e 20 69 66 20 74 68 65 |pens eve|n if the|
|00001590| 20 73 74 61 63 6b 20 6f | 6e 6c 79 20 63 6f 6e 74 | stack o|nly cont|
|000015a0| 61 69 6e 73 20 61 0d 0a | 72 65 66 65 72 65 6e 63 |ains a..|referenc|
|000015b0| 65 20 74 6f 20 61 20 6d | 61 74 72 69 78 20 69 6e |e to a m|atrix in|
|000015c0| 73 74 65 61 64 20 6f 66 | 20 61 20 63 6f 70 79 2e |stead of| a copy.|
|000015d0| 20 54 68 69 73 20 70 72 | 6f 62 6c 65 6d 20 77 61 | This pr|oblem wa|
|000015e0| 73 20 64 69 73 63 75 73 | 73 65 64 0d 0a 62 79 20 |s discus|sed..by |
|000015f0| 44 61 76 69 65 73 20 69 | 6e 20 68 69 73 20 6d 61 |Davies i|n his ma|
|00001600| 74 72 69 78 20 70 72 6f | 67 72 61 6d 20 4e 65 77 |trix pro|gram New|
|00001610| 6d 61 74 20 28 63 75 72 | 72 65 6e 74 6c 79 20 61 |mat (cur|rently a|
|00001620| 76 61 69 6c 61 62 6c 65 | 20 69 6e 0d 0a 74 68 65 |vailable| in..the|
|00001630| 20 42 6f 72 6c 61 6e 64 | 20 43 2b 2b 20 6c 69 62 | Borland| C++ lib|
|00001640| 72 61 72 79 20 6f 6e 20 | 43 6f 6d 70 75 73 65 72 |rary on |Compuser|
|00001650| 76 65 29 2e 0d 0a 0d 0a | 54 68 65 20 61 64 76 61 |ve).....|The adva|
|00001660| 6e 74 61 67 65 20 74 6f | 20 68 61 76 69 6e 67 20 |ntage to| having |
|00001670| 61 6e 20 65 78 70 6c 69 | 63 69 74 20 73 74 61 63 |an expli|cit stac|
|00001680| 6b 20 69 73 20 74 68 61 | 74 20 79 6f 75 20 63 61 |k is tha|t you ca|
|00001690| 6e 0d 0a 63 6f 6e 74 72 | 6f 6c 20 74 68 65 20 64 |n..contr|ol the d|
|000016a0| 65 6c 65 74 69 6f 6e 20 | 6f 66 20 74 68 65 20 74 |eletion |of the t|
|000016b0| 65 6d 70 6f 72 61 72 79 | 20 6d 61 74 72 69 63 65 |emporary| matrice|
|000016c0| 73 2e 20 54 68 65 0d 0a | 5c 76 65 72 62 2b 43 6c |s. The..|\verb+Cl|
|000016d0| 65 61 6e 73 74 61 63 6b | 28 29 2b 20 66 75 6e 63 |eanstack|()+ func|
|000016e0| 74 69 6f 6e 20 63 61 6e | 20 62 65 20 75 73 65 64 |tion can| be used|
|000016f0| 20 66 6f 72 20 67 61 72 | 62 61 67 65 20 63 6f 6c | for gar|bage col|
|00001700| 6c 65 63 74 69 6f 6e 0d | 0a 6f 66 20 74 65 6d 70 |lection.|.of temp|
|00001710| 6f 72 61 72 79 20 6d 61 | 74 72 69 63 65 73 2e 20 |orary ma|trices. |
|00001720| 49 74 20 69 73 20 63 61 | 6c 6c 65 64 20 69 6e 20 |It is ca|lled in |
|00001730| 6d 61 74 72 69 78 20 61 | 73 73 69 67 6e 6d 65 6e |matrix a|ssignmen|
|00001740| 74 2c 20 61 6e 64 0d 0a | 74 68 65 20 63 6f 70 79 |t, and..|the copy|
|00001750| 20 63 6f 6e 73 74 72 75 | 63 74 6f 72 2e 20 49 74 | constru|ctor. It|
|00001760| 20 69 73 20 61 6c 73 6f | 20 61 20 70 75 62 6c 69 | is also| a publi|
|00001770| 63 20 66 75 6e 63 74 69 | 6f 6e 2c 20 73 6f 20 69 |c functi|on, so i|
|00001780| 74 20 6d 61 79 0d 0a 61 | 6c 73 6f 20 62 65 20 63 |t may..a|lso be c|
|00001790| 61 6c 6c 65 64 20 65 78 | 70 6c 69 63 69 74 6c 79 |alled ex|plicitly|
|000017a0| 2e 20 49 74 27 73 20 6d | 79 20 6f 70 69 6e 69 6f |. It's m|y opinio|
|000017b0| 6e 20 74 68 61 74 20 74 | 68 65 20 6f 76 65 72 68 |n that t|he overh|
|000017c0| 65 61 64 20 6f 66 0d 0a | 6d 61 6e 69 70 75 6c 61 |ead of..|manipula|
|000017d0| 74 69 6e 67 20 61 6e 20 | 65 78 70 6c 69 63 69 74 |ting an |explicit|
|000017e0| 20 73 74 61 63 6b 20 6f | 75 74 77 65 69 67 68 73 | stack o|utweighs|
|000017f0| 20 74 68 65 20 73 74 6f | 72 61 67 65 20 70 72 6f | the sto|rage pro|
|00001800| 62 6c 65 6d 73 0d 0a 61 | 6e 64 20 73 74 61 63 6b |blems..a|nd stack|
|00001810| 20 6f 76 65 72 66 6c 6f | 77 20 70 72 6f 62 6c 65 | overflo|w proble|
|00001820| 6d 73 20 6f 66 20 6c 65 | 74 74 69 6e 67 20 74 68 |ms of le|tting th|
|00001830| 65 20 70 72 6f 67 72 61 | 6d 20 73 74 61 63 6b 20 |e progra|m stack |
|00001840| 64 6f 20 69 74 0d 0a 66 | 6f 72 20 79 6f 75 2e 20 |do it..f|or you. |
|00001850| 42 65 73 69 64 65 73 2c | 20 49 20 63 6f 75 6c 64 |Besides,| I could|
|00001860| 6e 27 74 20 66 69 67 75 | 72 65 20 6f 75 74 20 68 |n't figu|re out h|
|00001870| 6f 77 20 74 6f 20 6c 65 | 74 20 74 68 65 20 70 72 |ow to le|t the pr|
|00001880| 6f 67 72 61 6d 20 64 6f | 0d 0a 69 74 20 66 6f 72 |ogram do|..it for|
|00001890| 20 6d 65 2e 0d 0a 0d 0a | 5c 73 65 63 74 69 6f 6e | me.....|\section|
|000018a0| 7b 54 68 65 20 53 74 61 | 63 6b 7d 0d 0a 54 68 65 |{The Sta|ck}..The|
|000018b0| 20 63 6c 61 73 73 20 4d | 53 74 61 63 6b 20 69 73 | class M|Stack is|
|000018c0| 20 64 65 72 69 76 65 64 | 20 66 72 6f 6d 20 74 68 | derived| from th|
|000018d0| 65 20 56 4d 61 74 72 69 | 78 20 63 6c 61 73 73 2e |e VMatri|x class.|
|000018e0| 20 54 68 65 0d 0a 64 65 | 63 6c 61 72 61 74 69 6f | The..de|claratio|
|000018f0| 6e 20 69 73 20 67 69 76 | 65 6e 20 62 79 0d 0a 5c |n is giv|en by..\|
|00001900| 62 65 67 69 6e 7b 76 65 | 72 62 61 74 69 6d 7d 0d |begin{ve|rbatim}.|
|00001910| 0a 0d 0a 63 6c 61 73 73 | 20 4d 53 74 61 63 6b 3a |...class| MStack:|
|00001920| 20 70 75 62 6c 69 63 20 | 56 4d 61 74 72 69 78 20 | public |VMatrix |
|00001930| 7b 0d 0a 0d 0a 20 20 70 | 72 69 76 61 74 65 3a 0d |{.... p|rivate:.|
|00001940| 0a 0d 0a 20 20 20 69 6e | 74 20 73 74 61 63 6b 6c |... in|t stackl|
|00001950| 6f 63 2c 20 6c 65 76 65 | 6c 3b 0d 0a 20 20 20 4d |oc, leve|l;.. M|
|00001960| 53 74 61 63 6b 20 2a 6e | 65 78 74 3b 0d 0a 20 20 |Stack *n|ext;.. |
|00001970| 20 56 4d 61 74 72 69 78 | 26 20 50 6f 70 28 20 76 | VMatrix|& Pop( v|
|00001980| 6f 69 64 20 29 3b 0d 0a | 0d 0a 20 20 70 75 62 6c |oid );..|.. publ|
|00001990| 69 63 3a 0d 0a 0d 0a 20 | 20 20 20 4d 53 74 61 63 |ic:.... | MStac|
|000019a0| 6b 28 20 76 6f 69 64 20 | 29 3b 0d 0a 20 20 20 20 |k( void |);.. |
|000019b0| 76 6f 69 64 20 50 75 73 | 68 28 20 56 4d 61 74 72 |void Pus|h( VMatr|
|000019c0| 69 78 20 26 52 4f 70 20 | 29 3b 0d 0a 0d 0a 20 20 |ix &ROp |);.... |
|000019d0| 20 20 76 6f 69 64 20 49 | 6e 63 6c 65 76 65 6c 28 | void I|nclevel(|
|000019e0| 29 3b 0d 0a 20 20 20 20 | 76 6f 69 64 20 44 65 63 |);.. |void Dec|
|000019f0| 6c 65 76 65 6c 28 29 3b | 0d 0a 20 20 20 20 56 4d |level();|.. VM|
|00001a00| 61 74 72 69 78 20 26 44 | 65 63 52 65 74 75 72 6e |atrix &D|ecReturn|
|00001a10| 28 20 76 6f 69 64 20 29 | 7b 0d 0a 20 20 20 20 20 |( void )|{.. |
|00001a20| 20 20 20 20 44 65 63 6c | 65 76 65 6c 28 29 3b 0d | Decl|evel();.|
|00001a30| 0a 20 20 20 20 20 20 20 | 20 20 6e 65 78 74 2d 3e |. | next->|
|00001a40| 6c 65 76 65 6c 20 3d 20 | 6c 65 76 65 6c 3b 0d 0a |level = |level;..|
|00001a50| 20 20 20 20 20 20 20 20 | 20 72 65 74 75 72 6e 20 | | return |
|00001a60| 2a 20 28 28 56 4d 61 74 | 72 69 78 20 2a 29 20 74 |* ((VMat|rix *) t|
|00001a70| 68 69 73 2d 3e 6e 65 78 | 74 29 3b 0d 0a 20 20 20 |his->nex|t);.. |
|00001a80| 20 7d 0d 0a 20 20 20 20 | 56 4d 61 74 72 69 78 20 | }.. |VMatrix |
|00001a90| 26 52 65 74 75 72 6e 4d | 61 74 28 20 76 6f 69 64 |&ReturnM|at( void|
|00001aa0| 20 29 7b 0d 0a 20 20 20 | 20 20 20 20 20 20 6e 65 | ){.. | ne|
|00001ab0| 78 74 2d 3e 6c 65 76 65 | 6c 20 3d 20 6c 65 76 65 |xt->leve|l = leve|
|00001ac0| 6c 3b 0d 0a 20 20 20 20 | 20 20 20 20 20 72 65 74 |l;.. | ret|
|00001ad0| 75 72 6e 20 2a 20 28 28 | 56 4d 61 74 72 69 78 20 |urn * ((|VMatrix |
|00001ae0| 2a 29 20 74 68 69 73 2d | 3e 6e 65 78 74 29 3b 0d |*) this-|>next);.|
|00001af0| 0a 20 20 20 20 7d 0d 0a | 20 20 20 20 76 6f 69 64 |. }..| void|
|00001b00| 20 43 6c 65 61 6e 73 74 | 61 63 6b 28 20 76 6f 69 | Cleanst|ack( voi|
|00001b10| 64 20 29 3b 0d 0a 20 20 | 20 20 76 6f 69 64 20 50 |d );.. | void P|
|00001b20| 72 69 6e 74 53 74 61 63 | 6b 28 20 76 6f 69 64 20 |rintStac|k( void |
|00001b30| 29 3b 0d 0a 7d 3b 0d 0a | 0d 0a 65 78 74 65 72 6e |);..};..|..extern|
|00001b40| 20 4d 53 74 61 63 6b 20 | 2a 44 69 73 70 61 74 63 | MStack |*Dispatc|
|00001b50| 68 3b 0d 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |h;..\end|{verbati|
|00001b60| 6d 7d 0d 0a 4e 6f 74 65 | 20 74 68 65 20 6c 61 73 |m}..Note| the las|
|00001b70| 74 20 6c 69 6e 65 20 64 | 65 63 6c 61 72 65 73 20 |t line d|eclares |
|00001b80| 44 69 73 70 61 74 63 68 | 20 61 73 20 61 20 70 6f |Dispatch| as a po|
|00001b90| 69 6e 74 65 72 20 74 6f | 20 61 0d 0a 4d 53 74 61 |inter to| a..MSta|
|00001ba0| 63 6b 20 6f 62 6a 65 63 | 74 2e 20 49 74 20 69 73 |ck objec|t. It is|
|00001bb0| 20 61 6c 73 6f 20 64 65 | 63 6c 61 72 65 64 20 65 | also de|clared e|
|00001bc0| 78 74 65 72 6e 2e 20 54 | 68 65 20 65 78 74 65 72 |xtern. T|he exter|
|00001bd0| 6e 61 6c 0d 0a 64 65 63 | 6c 61 72 61 74 69 6f 6e |nal..dec|laration|
|00001be0| 20 69 73 20 75 73 65 64 | 20 69 6e 20 74 68 65 20 | is used| in the |
|00001bf0| 68 65 61 64 65 72 20 66 | 69 6c 65 20 56 49 52 54 |header f|ile VIRT|
|00001c00| 2e 48 20 73 6f 20 74 68 | 61 74 20 61 6c 6c 0d 0a |.H so th|at all..|
|00001c10| 6d 6f 64 75 6c 65 73 20 | 77 69 6c 6c 20 6b 6e 6f |modules |will kno|
|00001c20| 77 20 74 68 61 74 20 44 | 69 73 70 61 74 63 68 20 |w that D|ispatch |
|00001c30| 65 78 69 74 73 2c 20 61 | 6e 64 20 77 69 6c 6c 20 |exits, a|nd will |
|00001c40| 62 65 20 63 72 65 61 74 | 65 64 0d 0a 69 6e 20 74 |be creat|ed..in t|
|00001c50| 68 65 20 6d 6f 64 75 6c | 65 20 63 6f 6e 74 61 69 |he modul|e contai|
|00001c60| 6e 69 6e 67 20 74 68 65 | 20 6d 61 69 6e 20 70 72 |ning the| main pr|
|00001c70| 6f 67 72 61 6d 2e 20 0d | 0a 0d 0a 54 68 65 20 4d |ogram. .|...The M|
|00001c80| 53 74 61 63 6b 20 69 73 | 20 61 20 73 75 62 63 6c |Stack is| a subcl|
|00001c90| 61 73 73 20 6f 66 20 74 | 68 65 20 56 4d 61 74 72 |ass of t|he VMatr|
|00001ca0| 69 78 20 63 6c 61 73 73 | 2c 20 73 6f 20 69 74 0d |ix class|, so it.|
|00001cb0| 0a 69 6e 68 65 72 69 74 | 73 20 74 68 65 20 6d 65 |.inherit|s the me|
|00001cc0| 6d 62 65 72 73 20 61 6e | 64 20 64 61 74 61 20 6f |mbers an|d data o|
|00001cd0| 66 20 74 68 65 20 56 4d | 61 74 72 69 78 20 63 6c |f the VM|atrix cl|
|00001ce0| 61 73 73 2c 20 61 6e 64 | 20 68 61 73 0d 0a 61 63 |ass, and| has..ac|
|00001cf0| 63 65 73 73 20 74 6f 20 | 74 68 65 20 70 72 6f 74 |cess to |the prot|
|00001d00| 65 63 74 65 64 20 70 61 | 72 74 20 6f 66 20 74 68 |ected pa|rt of th|
|00001d10| 65 20 56 4d 61 74 72 69 | 78 20 63 6c 61 73 73 2e |e VMatri|x class.|
|00001d20| 20 54 68 65 0d 0a 72 65 | 6c 61 74 69 6f 6e 73 68 | The..re|lationsh|
|00001d30| 69 70 20 69 73 20 6e 6f | 74 20 73 74 72 69 63 74 |ip is no|t strict|
|00001d40| 6c 79 20 68 69 65 72 61 | 63 68 69 63 61 6c 20 62 |ly hiera|chical b|
|00001d50| 65 63 61 75 73 65 20 74 | 68 65 20 6d 61 74 72 69 |ecause t|he matri|
|00001d60| 78 0d 0a 63 6c 61 73 73 | 20 6d 75 73 74 20 63 61 |x..class| must ca|
|00001d70| 6c 6c 20 44 69 73 70 61 | 74 63 68 20 74 6f 20 61 |ll Dispa|tch to a|
|00001d80| 63 68 69 65 76 65 20 73 | 6f 6d 65 20 6f 66 20 69 |chieve s|ome of i|
|00001d90| 74 73 20 66 75 6e 63 74 | 69 6f 6e 73 2e 0d 0a 49 |ts funct|ions...I|
|00001da0| 20 63 61 6c 6c 20 69 74 | 20 61 20 73 79 6d 62 69 | call it| a symbi|
|00001db0| 6f 74 69 63 20 72 65 6c | 61 74 69 6f 6e 73 68 69 |otic rel|ationshi|
|00001dc0| 70 2c 20 66 6f 72 20 77 | 68 61 74 65 76 65 72 20 |p, for w|hatever |
|00001dd0| 74 68 61 74 27 73 0d 0a | 77 6f 72 74 68 2e 20 54 |that's..|worth. T|
|00001de0| 68 65 20 70 6f 69 6e 74 | 20 74 6f 20 72 65 6d 65 |he point| to reme|
|00001df0| 6d 62 65 72 20 69 73 20 | 74 68 61 74 20 44 69 73 |mber is |that Dis|
|00001e00| 70 61 74 63 68 20 6d 75 | 73 74 20 62 65 0d 0a 69 |patch mu|st be..i|
|00001e10| 6e 73 74 61 6e 74 69 61 | 74 65 64 20 61 73 20 61 |nstantia|ted as a|
|00001e20| 20 67 6c 6f 62 61 6c 20 | 64 61 74 61 20 6f 62 6a | global |data obj|
|00001e30| 65 63 74 20 66 6f 72 20 | 69 74 73 20 70 61 72 65 |ect for |its pare|
|00001e40| 6e 74 0d 0a 63 6c 61 73 | 73 20 74 6f 20 77 6f 72 |nt..clas|s to wor|
|00001e50| 6b 2e 0d 0a 0d 0a 5c 73 | 75 62 73 65 63 74 69 6f |k.....\s|ubsectio|
|00001e60| 6e 7b 54 68 65 20 50 72 | 69 76 61 74 65 20 50 61 |n{The Pr|ivate Pa|
|00001e70| 72 74 73 20 6f 66 20 4d | 53 74 61 63 6b 7d 0d 0a |rts of M|Stack}..|
|00001e80| 54 68 65 20 70 72 69 76 | 61 74 65 20 64 61 74 61 |The priv|ate data|
|00001e90| 20 6f 66 20 4d 53 74 61 | 63 6b 20 61 72 65 20 73 | of MSta|ck are s|
|00001ea0| 74 61 63 6b 6c 6f 63 2c | 20 6c 65 76 65 6c 20 61 |tackloc,| level a|
|00001eb0| 6e 64 20 6e 65 78 74 2e | 0d 0a 73 74 61 63 6b 6c |nd next.|..stackl|
|00001ec0| 6f 63 5c 69 6e 64 65 78 | 7b 4d 53 74 61 63 6b 21 |oc\index|{MStack!|
|00001ed0| 73 74 61 63 6b 6c 6f 63 | 7d 20 6b 65 65 70 73 20 |stackloc|} keeps |
|00001ee0| 74 72 61 63 6b 20 6f 66 | 20 68 6f 77 20 6d 61 6e |track of| how man|
|00001ef0| 79 0d 0a 6d 61 74 72 69 | 63 65 73 20 68 61 76 65 |y..matri|ces have|
|00001f00| 20 62 65 65 6e 20 70 75 | 73 68 65 64 20 6f 6e 74 | been pu|shed ont|
|00001f10| 6f 20 74 68 65 20 73 74 | 61 63 6b 2e 20 49 74 20 |o the st|ack. It |
|00001f20| 69 73 20 75 73 65 64 20 | 61 73 20 61 0d 0a 64 65 |is used |as a..de|
|00001f30| 62 75 67 67 69 6e 67 20 | 74 6f 6f 6c 2c 20 61 6e |bugging |tool, an|
|00001f40| 64 20 61 73 20 61 20 6c | 6f 6f 70 20 63 6f 75 6e |d as a l|oop coun|
|00001f50| 74 65 72 20 69 6e 20 50 | 72 69 6e 74 53 74 61 63 |ter in P|rintStac|
|00001f60| 6b 28 29 2e 0d 0a 0d 0a | 54 68 65 20 76 61 72 69 |k().....|The vari|
|00001f70| 61 62 6c 65 2c 20 6c 65 | 76 65 6c 5c 69 6e 64 65 |able, le|vel\inde|
|00001f80| 78 7b 4d 53 74 61 63 6b | 21 6c 65 76 65 6c 7d 2c |x{MStack|!level},|
|00001f90| 20 69 73 20 74 68 65 20 | 66 75 6e 63 74 69 6f 6e | is the |function|
|00001fa0| 20 6e 65 73 74 69 6e 67 | 0d 0a 6c 65 76 65 6c 2e | nesting|..level.|
|00001fb0| 20 57 68 65 6e 20 43 6c | 65 61 6e 53 74 61 63 6b | When Cl|eanStack|
|00001fc0| 28 29 20 69 73 20 63 61 | 6c 6c 65 64 2c 20 69 74 |() is ca|lled, it|
|00001fd0| 20 6f 6e 6c 79 20 70 6f | 70 73 20 6d 61 74 72 69 | only po|ps matri|
|00001fe0| 63 65 73 20 6f 66 66 0d | 0a 74 68 65 20 73 74 61 |ces off.|.the sta|
|00001ff0| 63 6b 20 77 68 65 72 65 | 20 6c 65 76 65 6c 20 69 |ck where| level i|
|00002000| 73 20 67 72 65 61 74 65 | 72 20 74 68 61 6e 20 6f |s greate|r than o|
|00002010| 72 20 65 71 75 61 6c 20 | 74 6f 0d 0a 44 69 73 70 |r equal |to..Disp|
|00002020| 61 74 63 68 2d 24 3e 24 | 6c 65 76 65 6c 2e 20 20 |atch-$>$|level. |
|00002030| 54 68 65 20 72 75 6c 65 | 20 6f 66 20 74 68 75 6d |The rule| of thum|
|00002040| 62 20 66 6f 72 20 61 6c | 74 65 72 69 6e 67 20 6c |b for al|tering l|
|00002050| 65 76 65 6c 20 69 73 20 | 74 68 61 74 0d 0a 61 20 |evel is |that..a |
|00002060| 66 75 6e 63 74 69 6f 6e | 20 75 73 65 73 20 6d 61 |function| uses ma|
|00002070| 74 72 69 78 20 61 73 73 | 69 67 6e 6d 65 6e 74 2c |trix ass|ignment,|
|00002080| 20 69 2e 65 2e 20 56 4d | 61 74 72 69 78 3a 3a 6f | i.e. VM|atrix::o|
|00002090| 70 65 72 61 74 6f 72 3d | 28 29 2e 0d 0a 54 68 69 |perator=|()...Thi|
|000020a0| 73 20 61 6c 6c 6f 77 73 | 20 65 61 63 68 20 66 75 |s allows| each fu|
|000020b0| 6e 63 74 69 6f 6e 20 74 | 6f 20 68 61 76 65 20 69 |nction t|o have i|
|000020c0| 74 73 20 6f 77 6e 20 6c | 6f 63 61 6c 20 73 74 61 |ts own l|ocal sta|
|000020d0| 63 6b 2c 20 62 75 74 20 | 61 6c 6c 0d 0a 6f 66 20 |ck, but |all..of |
|000020e0| 74 68 65 20 6c 6f 63 61 | 6c 20 73 74 61 63 6b 73 |the loca|l stacks|
|000020f0| 20 68 61 70 70 65 6e 20 | 74 6f 20 62 65 20 69 6e | happen |to be in|
|00002100| 20 74 68 65 20 73 61 6d | 65 20 6c 69 6e 6b 65 64 | the sam|e linked|
|00002110| 20 6c 69 73 74 2e 20 20 | 6c 65 76 65 6c 0d 0a 63 | list. |level..c|
|00002120| 61 6e 20 62 65 20 6d 6f | 64 69 66 69 65 64 20 62 |an be mo|dified b|
|00002130| 79 20 74 68 65 20 70 75 | 62 6c 69 63 20 6d 65 6d |y the pu|blic mem|
|00002140| 62 65 72 20 66 75 6e 63 | 74 69 6f 6e 73 20 44 65 |ber func|tions De|
|00002150| 63 6c 65 76 65 6c 28 29 | 20 61 6e 64 0d 0a 49 6e |clevel()| and..In|
|00002160| 63 6c 65 76 65 6c 28 29 | 2c 20 77 68 69 63 68 20 |clevel()|, which |
|00002170| 73 68 6f 75 6c 64 20 62 | 65 20 75 73 65 64 20 69 |should b|e used i|
|00002180| 6e 20 70 61 69 72 73 20 | 69 6e 20 66 75 6e 63 74 |n pairs |in funct|
|00002190| 69 6f 6e 73 2e 0d 0a 44 | 65 63 52 65 74 75 72 6e |ions...D|ecReturn|
|000021a0| 28 29 20 61 6c 73 6f 20 | 64 65 63 72 65 6d 65 6e |() also |decremen|
|000021b0| 74 73 20 6c 65 76 65 6c | 2e 0d 0a 0d 0a 54 68 65 |ts level|.....The|
|000021c0| 20 70 6f 69 6e 74 65 72 | 2c 20 6e 65 78 74 5c 69 | pointer|, next\i|
|000021d0| 6e 64 65 78 7b 4d 53 74 | 61 63 6b 21 6e 65 78 74 |ndex{MSt|ack!next|
|000021e0| 7d 2c 20 73 74 6f 72 65 | 73 20 74 68 65 20 61 64 |}, store|s the ad|
|000021f0| 64 72 65 73 73 20 6f 66 | 0d 0a 74 68 65 20 6e 65 |dress of|..the ne|
|00002200| 78 74 20 6d 61 74 72 69 | 78 20 69 6e 20 74 68 65 |xt matri|x in the|
|00002210| 20 73 74 61 63 6b 2e 20 | 54 68 75 73 2c 20 74 68 | stack. |Thus, th|
|00002220| 65 20 73 74 61 63 6b 20 | 69 73 20 61 20 73 69 6e |e stack |is a sin|
|00002230| 67 6c 79 0d 0a 6c 69 6e | 6b 65 64 20 6c 69 73 74 |gly..lin|ked list|
|00002240| 2e 20 54 68 65 20 6c 61 | 73 74 20 6d 61 74 72 69 |. The la|st matri|
|00002250| 78 20 69 6e 20 74 68 65 | 20 73 74 61 63 6b 20 73 |x in the| stack s|
|00002260| 74 6f 72 65 73 20 4e 55 | 4c 4c 20 69 6e 0d 0a 74 |tores NU|LL in..t|
|00002270| 68 65 20 76 61 6c 75 65 | 20 6f 66 20 6e 65 78 74 |he value| of next|
|00002280| 2e 20 20 41 6c 73 6f 2c | 20 74 68 65 20 6c 69 73 |. Also,| the lis|
|00002290| 74 20 63 61 6e 20 62 65 | 20 74 72 61 76 65 72 73 |t can be| travers|
|000022a0| 65 64 20 6f 6e 6c 79 20 | 62 79 0d 0a 6d 65 6d 62 |ed only |by..memb|
|000022b0| 65 72 20 66 75 6e 63 74 | 69 6f 6e 73 20 73 69 6e |er funct|ions sin|
|000022c0| 63 65 20 6e 65 78 74 20 | 69 73 20 61 20 70 72 69 |ce next |is a pri|
|000022d0| 76 61 74 65 20 65 6c 65 | 6d 65 6e 74 2e 20 54 68 |vate ele|ment. Th|
|000022e0| 65 0d 0a 72 65 66 65 72 | 65 6e 63 65 20 73 74 6f |e..refer|ence sto|
|000022f0| 72 65 64 20 69 6e 20 44 | 69 73 70 61 74 63 68 2d |red in D|ispatch-|
|00002300| 24 3e 24 6e 65 78 74 20 | 69 73 20 74 68 65 20 61 |$>$next |is the a|
|00002310| 64 64 72 65 73 73 20 72 | 65 74 75 72 6e 65 64 0d |ddress r|eturned.|
|00002320| 0a 62 79 20 44 65 63 52 | 65 74 75 72 6e 28 29 20 |.by DecR|eturn() |
|00002330| 61 6e 64 20 52 65 74 75 | 72 6e 4d 61 74 28 29 2e |and Retu|rnMat().|
|00002340| 0d 0a 0d 0a 54 68 65 20 | 70 72 69 76 61 74 65 20 |....The |private |
|00002350| 70 61 72 74 20 6f 66 20 | 4d 53 74 61 63 6b 20 61 |part of |MStack a|
|00002360| 6c 73 6f 20 68 61 73 20 | 6f 6e 65 20 6d 65 6d 62 |lso has |one memb|
|00002370| 65 72 20 66 75 6e 63 74 | 69 6f 6e 2c 0d 0a 50 6f |er funct|ion,..Po|
|00002380| 70 28 29 5c 69 6e 64 65 | 78 7b 4d 53 74 61 63 6b |p()\inde|x{MStack|
|00002390| 21 50 6f 70 28 29 7d 2e | 20 20 50 6f 70 28 29 20 |!Pop()}.| Pop() |
|000023a0| 69 73 20 6f 6e 6c 79 20 | 63 61 6c 6c 65 64 20 62 |is only |called b|
|000023b0| 79 0d 0a 43 6c 65 61 6e | 53 74 61 63 6b 28 29 2c |y..Clean|Stack(),|
|000023c0| 20 73 6f 20 69 74 20 69 | 73 20 6e 6f 74 20 6e 65 | so it i|s not ne|
|000023d0| 65 64 65 64 20 61 73 20 | 61 20 70 75 62 6c 69 63 |eded as |a public|
|000023e0| 20 66 75 6e 63 74 69 6f | 6e 2e 0d 0a 50 6f 70 28 | functio|n...Pop(|
|000023f0| 29 20 77 6f 72 6b 73 20 | 6c 69 6b 65 20 6d 6f 73 |) works |like mos|
|00002400| 74 20 6f 74 68 65 72 20 | 70 6f 70 20 72 6f 75 74 |t other |pop rout|
|00002410| 69 6e 65 73 2e 20 49 74 | 20 72 65 61 73 73 69 67 |ines. It| reassig|
|00002420| 6e 73 0d 0a 44 69 73 70 | 61 74 63 68 2d 24 3e 24 |ns..Disp|atch-$>$|
|00002430| 6e 65 78 74 2c 20 61 6e | 64 20 64 65 6c 65 74 65 |next, an|d delete|
|00002440| 73 20 74 68 65 20 6d 61 | 74 72 69 78 20 70 6f 69 |s the ma|trix poi|
|00002450| 6e 74 65 64 20 74 6f 20 | 62 79 20 74 68 65 0d 0a |nted to |by the..|
|00002460| 6f 72 69 67 69 6e 61 6c | 20 44 69 73 70 61 74 63 |original| Dispatc|
|00002470| 68 2d 24 3e 24 6e 65 78 | 74 2e 20 50 6f 70 28 29 |h-$>$nex|t. Pop()|
|00002480| 20 61 6c 73 6f 20 64 65 | 63 72 65 6d 65 6e 74 73 | also de|crements|
|00002490| 20 73 74 61 63 6b 6c 6f | 63 2e 0d 0a 50 6f 70 28 | stacklo|c...Pop(|
|000024a0| 29 20 73 74 6f 70 73 20 | 74 68 65 20 70 72 6f 67 |) stops |the prog|
|000024b0| 72 61 6d 20 69 66 20 73 | 74 61 63 6b 6c 6f 63 20 |ram if s|tackloc |
|000024c0| 62 65 63 6f 6d 65 73 20 | 7a 65 72 6f 20 6f 72 20 |becomes |zero or |
|000024d0| 69 66 0d 0a 44 69 73 70 | 61 74 63 68 2d 24 3e 24 |if..Disp|atch-$>$|
|000024e0| 6e 65 78 74 20 69 73 20 | 4e 55 4c 4c 2e 0d 0a 0d |next is |NULL....|
|000024f0| 0a 5c 73 75 62 73 65 63 | 74 69 6f 6e 7b 54 68 65 |.\subsec|tion{The|
|00002500| 20 50 75 62 6c 69 63 20 | 50 61 72 74 73 20 6f 66 | Public |Parts of|
|00002510| 20 4d 53 74 61 63 6b 7d | 0d 0a 41 6c 6c 20 6f 66 | MStack}|..All of|
|00002520| 20 74 68 65 20 73 74 61 | 63 6b 20 65 6c 65 6d 65 | the sta|ck eleme|
|00002530| 6e 74 73 20 61 72 65 20 | 61 6c 6c 6f 63 61 74 65 |nts are |allocate|
|00002540| 64 20 6f 6e 20 74 68 65 | 20 68 65 61 70 2c 20 73 |d on the| heap, s|
|00002550| 6f 0d 0a 74 68 65 79 20 | 77 69 6c 6c 20 6e 6f 74 |o..they |will not|
|00002560| 20 65 78 61 75 73 74 20 | 74 68 65 20 70 72 6f 67 | exaust |the prog|
|00002570| 72 61 6d 20 73 74 61 63 | 6b 20 73 70 61 63 65 2e |ram stac|k space.|
|00002580| 20 54 68 65 79 20 6d 61 | 79 0d 0a 68 6f 77 65 76 | They ma|y..howev|
|00002590| 65 72 20 65 78 61 75 73 | 74 20 74 68 65 20 68 65 |er exaus|t the he|
|000025a0| 61 70 20 69 66 20 74 68 | 65 72 65 20 61 72 65 20 |ap if th|ere are |
|000025b0| 74 6f 6f 20 6d 61 6e 79 | 20 73 74 61 63 6b 0d 0a |too many| stack..|
|000025c0| 6d 61 74 72 69 63 65 73 | 20 61 6c 6c 6f 63 61 74 |matrices| allocat|
|000025d0| 65 64 2e 20 54 68 65 20 | 63 6f 6e 73 74 72 75 63 |ed. The |construc|
|000025e0| 74 6f 72 2c 0d 0a 4d 53 | 74 61 63 6b 28 29 5c 69 |tor,..MS|tack()\i|
|000025f0| 6e 64 65 78 7b 4d 53 74 | 61 63 6b 21 63 6f 6e 73 |ndex{MSt|ack!cons|
|00002600| 74 72 75 63 74 6f 72 7d | 2c 20 69 73 20 63 61 6c |tructor}|, is cal|
|00002610| 6c 65 64 20 66 69 72 73 | 74 20 62 79 20 74 68 65 |led firs|t by the|
|00002620| 20 63 72 65 61 74 69 6f | 6e 20 6f 66 0d 0a 44 69 | creatio|n of..Di|
|00002630| 73 70 61 74 63 68 2e 20 | 54 68 65 20 66 69 72 73 |spatch. |The firs|
|00002640| 74 20 63 61 6c 6c 20 74 | 6f 20 74 68 65 20 63 6f |t call t|o the co|
|00002650| 6e 73 74 72 75 63 74 6f | 72 20 73 65 74 73 20 6c |nstructo|r sets l|
|00002660| 65 76 65 6c 20 3d 20 31 | 2e 0d 0a 41 20 73 74 61 |evel = 1|...A sta|
|00002670| 74 69 63 20 69 6e 74 20 | 72 65 63 6f 72 64 73 20 |tic int |records |
|00002680| 74 68 65 20 66 61 63 74 | 20 74 68 61 74 20 44 69 |the fact| that Di|
|00002690| 73 70 61 74 63 68 20 68 | 61 73 0d 0a 62 65 65 6e |spatch h|as..been|
|000026a0| 20 63 72 65 61 74 65 64 | 2e 20 41 6c 6c 20 6f 74 | created|. All ot|
|000026b0| 68 65 72 20 63 61 6c 6c | 73 20 74 6f 20 74 68 65 |her call|s to the|
|000026c0| 20 63 6f 6e 73 74 72 75 | 63 74 6f 72 20 61 72 65 | constru|ctor are|
|000026d0| 0d 0a 74 68 72 6f 75 67 | 68 20 74 68 65 20 50 75 |..throug|h the Pu|
|000026e0| 73 68 28 29 20 66 75 6e | 63 74 69 6f 6e 2e 5c 66 |sh() fun|ction.\f|
|000026f0| 6f 6f 74 6e 6f 74 65 7b | 20 49 20 63 61 6e 6e 6f |ootnote{| I canno|
|00002700| 74 20 73 65 65 20 61 20 | 72 65 61 73 6f 6e 20 66 |t see a |reason f|
|00002710| 6f 72 0d 0a 64 69 72 65 | 63 74 6c 79 20 61 6c 6c |or..dire|ctly all|
|00002720| 6f 63 61 74 69 6e 67 20 | 61 6e 6f 74 68 65 72 20 |ocating |another |
|00002730| 4d 53 74 61 63 6b 20 6f | 74 68 65 72 20 74 68 61 |MStack o|ther tha|
|00002740| 6e 20 44 69 73 70 61 74 | 63 68 2c 0d 0a 73 69 6e |n Dispat|ch,..sin|
|00002750| 63 65 20 74 68 65 20 6d | 61 74 72 69 78 20 66 75 |ce the m|atrix fu|
|00002760| 6e 63 74 69 6f 6e 73 20 | 70 75 73 68 20 74 68 65 |nctions |push the|
|00002770| 69 72 20 72 65 73 75 6c | 74 73 20 6f 6e 74 6f 0d |ir resul|ts onto.|
|00002780| 0a 44 69 73 70 61 74 63 | 68 2e 20 4d 61 79 62 65 |.Dispatc|h. Maybe|
|00002790| 20 73 6f 6d 65 6f 6e 65 | 20 77 69 74 68 20 61 20 | someone| with a |
|000027a0| 70 61 72 61 6c 6c 65 6c | 20 70 72 6f 63 65 73 73 |parallel| process|
|000027b0| 6f 72 0d 0a 77 6f 75 6c | 64 20 77 61 6e 74 20 73 |or..woul|d want s|
|000027c0| 65 76 65 72 61 6c 20 69 | 6e 64 65 70 65 6e 64 65 |everal i|ndepende|
|000027d0| 6e 74 20 73 74 61 63 6b | 73 2c 20 62 75 74 20 74 |nt stack|s, but t|
|000027e0| 68 65 20 72 65 73 74 20 | 6f 66 20 74 68 65 0d 0a |he rest |of the..|
|000027f0| 70 72 6f 67 72 61 6d 20 | 77 6f 75 6c 64 20 68 61 |program |would ha|
|00002800| 76 65 20 74 6f 20 62 65 | 20 72 65 77 72 69 74 74 |ve to be| rewritt|
|00002810| 65 6e 2e 20 54 68 65 20 | 76 6d 6d 20 73 79 73 74 |en. The |vmm syst|
|00002820| 65 6d 20 77 6f 75 6c 64 | 0d 0a 6e 65 65 64 20 74 |em would|..need t|
|00002830| 6f 20 62 65 20 73 63 72 | 61 70 70 65 64 20 74 6f |o be scr|apped to|
|00002840| 6f 2e 20 49 74 27 73 20 | 63 6c 65 61 72 20 59 41 |o. It's |clear YA|
|00002850| 4d 50 20 69 73 20 61 20 | 50 43 20 70 72 6f 67 72 |MP is a |PC progr|
|00002860| 61 6d 7d 0d 0a 4f 74 68 | 65 72 77 69 73 65 2c 20 |am}..Oth|erwise, |
|00002870| 74 68 65 20 63 6f 6e 73 | 74 72 75 63 74 6f 72 20 |the cons|tructor |
|00002880| 69 6e 69 74 69 61 6c 69 | 7a 65 73 20 73 74 61 63 |initiali|zes stac|
|00002890| 6b 6c 6f 63 3d 30 2c 20 | 6c 65 76 65 6c 3d 30 0d |kloc=0, |level=0.|
|000028a0| 0a 61 6e 64 20 6e 65 78 | 74 20 3d 20 4e 55 4c 4c |.and nex|t = NULL|
|000028b0| 2e 20 50 75 73 68 28 29 | 20 66 69 78 65 73 20 74 |. Push()| fixes t|
|000028c0| 68 69 73 2e 20 54 68 65 | 72 65 20 69 73 20 6e 6f |his. The|re is no|
|000028d0| 20 64 65 73 74 72 75 63 | 74 6f 72 0d 0a 66 6f 72 | destruc|tor..for|
|000028e0| 20 4d 53 74 61 63 6b 20 | 6f 62 6a 65 63 74 73 2e | MStack |objects.|
|000028f0| 20 54 68 65 79 20 61 72 | 65 20 64 65 6c 65 74 65 | They ar|e delete|
|00002900| 64 20 62 79 20 70 6f 70 | 2e 0d 0a 0d 0a 50 75 73 |d by pop|.....Pus|
|00002910| 68 28 29 5c 69 6e 64 65 | 78 7b 4d 53 74 61 63 6b |h()\inde|x{MStack|
|00002920| 21 50 75 73 68 28 29 7d | 20 63 72 65 61 74 65 73 |!Push()}| creates|
|00002930| 20 61 20 4d 53 74 61 63 | 6b 20 6f 62 6a 65 63 74 | a MStac|k object|
|00002940| 20 6f 6e 20 74 68 65 20 | 68 65 61 70 2c 0d 0a 74 | on the |heap,..t|
|00002950| 68 65 6e 20 69 6e 73 65 | 72 74 73 20 69 74 20 69 |hen inse|rts it i|
|00002960| 6e 74 6f 20 74 68 65 20 | 73 74 61 63 6b 2e 20 48 |nto the |stack. H|
|00002970| 6f 77 65 76 65 72 20 74 | 68 65 20 6d 61 74 72 69 |owever t|he matri|
|00002980| 78 20 73 74 6f 72 65 64 | 20 69 6e 0d 0a 4d 53 74 |x stored| in..MSt|
|00002990| 61 63 6b 20 69 73 20 61 | 20 72 65 66 65 72 65 6e |ack is a| referen|
|000029a0| 63 65 20 74 6f 20 74 68 | 65 20 62 61 73 65 20 76 |ce to th|e base v|
|000029b0| 65 63 74 6f 72 20 69 6e | 20 74 68 65 20 70 75 73 |ector in| the pus|
|000029c0| 68 65 64 20 6d 61 74 72 | 69 78 2e 0d 0a 49 74 20 |hed matr|ix...It |
|000029d0| 61 6c 73 6f 20 69 6e 63 | 72 65 6d 65 6e 74 73 20 |also inc|rements |
|000029e0| 44 69 73 70 61 74 63 68 | 2d 24 3e 24 73 74 61 63 |Dispatch|-$>$stac|
|000029f0| 6b 6c 6f 63 20 61 6e 64 | 20 73 74 6f 72 65 73 20 |kloc and| stores |
|00002a00| 69 74 20 69 6e 20 74 68 | 65 20 6e 65 77 0d 0a 4d |it in th|e new..M|
|00002a10| 53 74 61 63 6b 20 6f 62 | 6a 65 63 74 2e 20 49 74 |Stack ob|ject. It|
|00002a20| 20 61 6c 73 6f 20 73 74 | 6f 72 65 73 20 44 69 73 | also st|ores Dis|
|00002a30| 70 61 74 63 68 2d 24 3e | 24 6c 65 76 65 6c 20 69 |patch-$>|$level i|
|00002a40| 6e 20 74 68 65 20 6e 65 | 77 0d 0a 6f 62 6a 65 63 |n the ne|w..objec|
|00002a50| 74 2e 20 20 44 69 73 70 | 61 74 63 68 2d 24 3e 24 |t. Disp|atch-$>$|
|00002a60| 50 75 73 68 28 29 20 73 | 68 6f 75 6c 64 20 62 65 |Push() s|hould be|
|00002a70| 20 63 61 6c 6c 65 64 20 | 62 65 66 6f 72 65 20 63 | called |before c|
|00002a80| 61 6c 6c 69 6e 67 0d 0a | 44 65 63 52 65 74 75 72 |alling..|DecRetur|
|00002a90| 6e 28 29 20 6f 72 20 52 | 65 74 75 72 6e 4d 61 74 |n() or R|eturnMat|
|00002aa0| 28 29 2e 20 0d 0a 0d 0a | 45 61 72 6c 69 65 72 20 |(). ....|Earlier |
|00002ab0| 76 65 72 73 69 6f 6e 73 | 20 6f 66 20 50 75 73 68 |versions| of Push|
|00002ac0| 28 29 20 68 61 64 20 73 | 70 65 65 64 20 70 72 6f |() had s|peed pro|
|00002ad0| 62 6c 65 6d 73 20 62 65 | 63 61 75 73 65 20 50 75 |blems be|cause Pu|
|00002ae0| 73 68 28 29 0d 0a 63 6f | 70 69 65 64 20 69 74 73 |sh()..co|pied its|
|00002af0| 20 61 72 67 75 6d 65 6e | 74 20 69 6e 74 6f 20 74 | argumen|t into t|
|00002b00| 68 65 20 6e 65 77 20 73 | 74 61 63 6b 20 6f 62 6a |he new s|tack obj|
|00002b10| 65 63 74 2e 20 54 68 65 | 20 63 75 72 72 65 6e 74 |ect. The| current|
|00002b20| 0d 0a 76 65 72 73 69 6f | 6e 20 75 73 65 73 20 61 |..versio|n uses a|
|00002b30| 20 64 65 65 70 20 63 6f | 70 79 20 74 65 63 68 6e | deep co|py techn|
|00002b40| 69 71 75 65 20 5c 69 6e | 64 65 78 7b 4d 53 74 61 |ique \in|dex{MSta|
|00002b50| 63 6b 21 64 65 65 70 20 | 63 6f 70 79 7d 20 66 6f |ck!deep |copy} fo|
|00002b60| 72 0d 0a 73 74 6f 72 69 | 6e 67 20 73 74 61 63 6b |r..stori|ng stack|
|00002b70| 20 6d 61 74 72 69 63 65 | 73 2e 20 54 68 65 20 64 | matrice|s. The d|
|00002b80| 65 65 70 20 63 6f 70 79 | 20 6d 65 74 68 6f 64 20 |eep copy| method |
|00002b90| 62 6f 6f 73 74 65 64 20 | 74 68 65 20 73 70 65 65 |boosted |the spee|
|00002ba0| 64 0d 0a 6f 66 20 6d 79 | 20 70 72 6f 67 72 61 6d |d..of my| program|
|00002bb0| 73 20 62 79 20 61 62 6f | 75 74 20 31 35 20 74 6f |s by abo|ut 15 to|
|00002bc0| 20 32 30 20 70 65 72 63 | 65 6e 74 2e 20 50 75 73 | 20 perc|ent. Pus|
|00002bd0| 68 28 29 20 63 72 65 61 | 74 65 73 20 74 68 65 0d |h() crea|tes the.|
|00002be0| 0a 72 65 66 65 72 65 6e | 63 65 20 62 79 20 61 20 |.referen|ce by a |
|00002bf0| 63 61 6c 6c 20 74 6f 20 | 74 68 65 20 56 4d 61 74 |call to |the VMat|
|00002c00| 72 69 78 20 66 75 6e 63 | 74 69 6f 6e 20 4e 65 77 |rix func|tion New|
|00002c10| 52 65 66 65 72 65 6e 63 | 65 28 29 2e 0d 0a 4e 65 |Referenc|e()...Ne|
|00002c20| 77 52 65 66 65 72 65 6e | 63 65 28 29 20 5c 69 6e |wReferen|ce() \in|
|00002c30| 64 65 78 7b 56 4d 61 74 | 72 69 78 21 4e 65 77 52 |dex{VMat|rix!NewR|
|00002c40| 65 66 65 72 65 6e 63 65 | 28 29 7d 20 69 6e 63 72 |eference|()} incr|
|00002c50| 65 6d 65 6e 74 73 20 74 | 68 65 0d 0a 76 61 72 69 |ements t|he..vari|
|00002c60| 61 62 6c 65 20 5c 76 65 | 72 62 2b 6e 72 65 66 73 |able \ve|rb+nrefs|
|00002c70| 2b 20 69 6e 20 74 68 65 | 20 62 61 73 65 20 76 65 |+ in the| base ve|
|00002c80| 63 74 6f 72 2e 20 49 6e | 20 74 68 65 20 69 6e 2d |ctor. In| the in-|
|00002c90| 72 61 6d 20 76 65 72 73 | 69 6f 6e 2c 0d 0a 5c 76 |ram vers|ion,..\v|
|00002ca0| 65 72 62 2b 6e 72 65 66 | 73 2b 20 69 73 20 69 6e |erb+nref|s+ is in|
|00002cb0| 63 72 65 6d 65 6e 74 65 | 64 20 69 6e 20 74 68 65 |cremente|d in the|
|00002cc0| 20 76 64 6f 75 62 20 73 | 74 72 75 63 74 75 72 65 | vdoub s|tructure|
|00002cd0| 2e 20 49 6e 20 74 68 65 | 0d 0a 76 69 72 74 75 61 |. In the|..virtua|
|00002ce0| 6c 20 76 65 72 73 69 6f | 6e 2c 20 5c 76 65 72 62 |l versio|n, \verb|
|00002cf0| 2b 6e 72 65 66 73 2b 20 | 69 73 20 69 6e 63 72 65 |+nrefs+ |is incre|
|00002d00| 6d 65 6e 74 65 64 20 69 | 6e 20 74 68 65 20 68 64 |mented i|n the hd|
|00002d10| 72 0d 0a 73 74 72 75 63 | 74 75 72 65 2e 20 49 6e |r..struc|ture. In|
|00002d20| 20 65 69 74 68 65 72 20 | 63 61 73 65 2c 20 74 68 | either |case, th|
|00002d30| 65 20 62 61 73 65 20 76 | 65 63 74 6f 72 20 69 73 |e base v|ector is|
|00002d40| 20 6e 6f 74 20 66 72 65 | 65 64 20 75 6e 74 69 6c | not fre|ed until|
|00002d50| 20 0d 0a 5c 76 65 72 62 | 2b 6e 72 65 66 73 2b 20 | ..\verb|+nrefs+ |
|00002d60| 69 73 20 7a 65 72 6f 2e | 20 48 6f 77 65 76 65 72 |is zero.| However|
|00002d70| 2c 20 74 68 65 20 72 65 | 73 74 20 6f 66 20 74 68 |, the re|st of th|
|00002d80| 65 20 76 69 72 74 75 61 | 6c 20 6d 61 74 72 69 78 |e virtua|l matrix|
|00002d90| 20 69 73 20 64 65 6c 65 | 74 65 64 2e 20 0d 0a 0d | is dele|ted. ...|
|00002da0| 0a 54 68 65 20 73 74 61 | 63 6b 20 6d 61 74 72 69 |.The sta|ck matri|
|00002db0| 63 65 73 20 73 68 61 72 | 65 20 74 68 65 20 62 61 |ces shar|e the ba|
|00002dc0| 73 65 20 76 65 63 74 6f | 72 20 77 69 74 68 20 74 |se vecto|r with t|
|00002dd0| 68 65 20 70 75 73 68 65 | 64 20 6d 61 74 72 69 78 |he pushe|d matrix|
|00002de0| 2c 0d 0a 61 6e 64 20 68 | 65 6e 63 65 20 79 6f 75 |,..and h|ence you|
|00002df0| 20 68 61 76 65 20 69 6e | 64 69 72 65 63 74 20 61 | have in|direct a|
|00002e00| 63 63 65 73 73 20 74 6f | 20 74 68 65 20 73 74 61 |ccess to| the sta|
|00002e10| 63 6b 20 6d 61 74 72 69 | 78 2e 20 54 68 69 73 0d |ck matri|x. This.|
|00002e20| 0a 61 63 63 65 73 73 20 | 69 73 20 64 69 66 66 65 |.access |is diffe|
|00002e30| 72 65 6e 74 20 66 72 6f | 6d 20 74 68 61 74 20 69 |rent fro|m that i|
|00002e40| 6e 20 45 63 6b 6c 65 20 | 5c 63 69 74 65 7b 45 4b |n Eckle |\cite{EK|
|00002e50| 3a 55 43 7d 20 77 68 65 | 72 65 20 49 0d 0a 66 6f |:UC} whe|re I..fo|
|00002e60| 75 6e 64 20 74 68 65 20 | 64 65 65 70 2d 63 6f 70 |und the |deep-cop|
|00002e70| 79 20 74 65 63 68 6e 69 | 71 75 65 2e 20 20 41 6c |y techni|que. Al|
|00002e80| 74 68 6f 75 67 68 20 49 | 20 63 61 6e 27 74 20 74 |though I| can't t|
|00002e90| 68 69 6e 6b 20 6f 66 20 | 77 68 79 0d 0a 79 6f 75 |hink of |why..you|
|00002ea0| 20 77 6f 75 6c 64 20 77 | 61 6e 74 20 74 68 69 73 | would w|ant this|
|00002eb0| 20 61 63 63 65 73 73 2c | 20 68 65 72 65 20 69 73 | access,| here is|
|00002ec0| 20 68 6f 77 20 69 74 20 | 63 61 6e 20 62 65 20 61 | how it |can be a|
|00002ed0| 63 63 6f 6d 70 6c 69 73 | 68 65 64 2e 0d 0a 0d 0a |ccomplis|hed.....|
|00002ee0| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00002ef0| 0d 0a 20 20 20 20 20 20 | 20 20 2e 0d 0a 20 20 20 |.. | ... |
|00002f00| 20 20 20 20 20 2e 0d 0a | 20 20 20 20 20 20 20 20 | ...| |
|00002f10| 2e 0d 0a 20 20 20 20 20 | 20 20 20 56 4d 61 74 72 |... | VMatr|
|00002f20| 69 78 20 42 20 3d 20 54 | 72 61 6e 28 58 29 2a 58 |ix B = T|ran(X)*X|
|00002f30| 3b 0d 0a 20 20 20 20 20 | 20 20 20 44 69 73 70 61 |;.. | Dispa|
|00002f40| 74 63 68 2d 3e 50 75 73 | 68 28 42 29 3b 0d 0a 20 |tch->Pus|h(B);.. |
|00002f50| 20 20 20 20 20 20 20 42 | 2e 4d 28 31 2c 31 29 20 | B|.M(1,1) |
|00002f60| 3d 20 32 2e 30 3b 0d 0a | 20 20 20 20 20 20 20 20 |= 2.0;..| |
|00002f70| 72 65 74 75 72 6e 20 44 | 69 73 70 61 74 63 68 2d |return D|ispatch-|
|00002f80| 3e 44 65 63 52 65 74 75 | 72 6e 28 29 3b 0d 0a 20 |>DecRetu|rn();.. |
|00002f90| 20 7d 0d 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 | }..\end|{verbati|
|00002fa0| 6d 7d 0d 0a 0d 0a 4e 6f | 74 65 20 73 69 6e 63 65 |m}....No|te since|
|00002fb0| 20 74 68 65 20 73 74 61 | 63 6b 20 74 6f 70 20 6d | the sta|ck top m|
|00002fc0| 61 74 72 69 78 20 73 68 | 61 72 65 73 20 74 68 65 |atrix sh|ares the|
|00002fd0| 20 62 61 73 65 20 76 65 | 63 74 6f 72 20 77 69 74 | base ve|ctor wit|
|00002fe0| 68 20 42 2c 0d 0a 74 68 | 65 20 61 73 73 69 67 6e |h B,..th|e assign|
|00002ff0| 6d 65 6e 74 20 77 72 69 | 74 65 73 20 32 2e 30 20 |ment wri|tes 2.0 |
|00003000| 69 6e 20 62 6f 74 68 20 | 42 28 31 2c 31 29 20 61 |in both |B(1,1) a|
|00003010| 6e 64 20 74 68 65 20 28 | 31 2c 31 29 20 65 6c 65 |nd the (|1,1) ele|
|00003020| 6d 65 6e 74 0d 0a 6f 66 | 20 74 68 65 20 73 74 61 |ment..of| the sta|
|00003030| 63 6b 20 74 6f 70 2e 20 | 54 68 75 73 20 74 68 65 |ck top. |Thus the|
|00003040| 20 6d 61 74 72 69 78 20 | 70 75 73 68 65 64 20 6f | matrix |pushed o|
|00003050| 6e 74 6f 20 74 68 65 20 | 73 74 61 63 6b 20 77 69 |nto the |stack wi|
|00003060| 6c 6c 20 62 65 0d 0a 64 | 69 66 66 65 72 65 6e 74 |ll be..d|ifferent|
|00003070| 20 66 72 6f 6d 20 74 68 | 65 20 6d 61 74 72 69 78 | from th|e matrix|
|00003080| 20 74 68 61 74 20 69 73 | 20 72 65 74 75 72 6e 65 | that is| returne|
|00003090| 64 20 62 79 20 74 68 65 | 20 66 75 6e 63 74 69 6f |d by the| functio|
|000030a0| 6e 20 63 61 6c 6c 2e 0d | 0a 54 68 65 20 6f 6e 6c |n call..|.The onl|
|000030b0| 79 20 70 6c 61 63 65 20 | 77 68 65 72 65 20 74 68 |y place |where th|
|000030c0| 69 73 20 63 6f 75 6c 64 | 20 62 65 20 61 20 70 72 |is could| be a pr|
|000030d0| 6f 62 6c 65 6d 20 69 73 | 20 6f 6e 20 74 68 65 20 |oblem is| on the |
|000030e0| 73 74 61 63 6b 20 74 6f | 70 0d 0a 61 6e 64 20 6e |stack to|p..and n|
|000030f0| 6f 6e 65 20 6f 66 20 74 | 68 65 20 6f 74 68 65 72 |one of t|he other|
|00003100| 20 6d 61 74 72 69 63 65 | 73 20 69 6e 20 74 68 65 | matrice|s in the|
|00003110| 20 73 74 61 63 6b 2e 20 | 54 68 69 73 20 69 73 20 | stack. |This is |
|00003120| 62 65 63 61 75 73 65 20 | 74 68 65 0d 0a 73 74 61 |because |the..sta|
|00003130| 63 6b 20 74 6f 70 20 69 | 73 20 74 68 65 20 6d 61 |ck top i|s the ma|
|00003140| 74 72 69 78 20 74 68 61 | 74 20 69 73 20 72 65 74 |trix tha|t is ret|
|00003150| 75 72 6e 65 64 20 69 6e | 20 66 75 6e 63 74 69 6f |urned in| functio|
|00003160| 6e 20 63 61 6c 6c 73 2e | 20 20 49 0d 0a 61 64 76 |n calls.| I..adv|
|00003170| 69 73 65 20 61 67 61 69 | 6e 73 74 20 75 73 69 6e |ise agai|nst usin|
|00003180| 67 20 74 68 69 73 20 74 | 72 69 63 6b 2e 20 41 67 |g this t|rick. Ag|
|00003190| 61 69 6e 20 49 20 73 61 | 79 2c 20 7b 5c 65 6d 0d |ain I sa|y, {\em.|
|000031a0| 0a 44 69 73 70 61 74 63 | 68 2d 24 3e 24 50 75 73 |.Dispatc|h-$>$Pus|
|000031b0| 68 28 29 20 73 68 6f 75 | 6c 64 20 6f 6e 6c 79 20 |h() shou|ld only |
|000031c0| 62 65 20 63 61 6c 6c 65 | 64 20 69 6d 6d 65 64 69 |be calle|d immedi|
|000031d0| 61 74 65 6c 79 20 62 65 | 66 6f 72 65 20 63 61 6c |ately be|fore cal|
|000031e0| 6c 69 6e 67 0d 0a 44 65 | 63 52 65 74 75 72 6e 28 |ling..De|cReturn(|
|000031f0| 29 20 6f 72 20 52 65 74 | 75 72 6e 4d 61 74 28 29 |) or Ret|urnMat()|
|00003200| 7d 2e 0d 0a 0d 0a 44 65 | 63 6c 65 76 65 6c 28 29 |}.....De|clevel()|
|00003210| 5c 69 6e 64 65 78 7b 4d | 53 74 61 63 6b 21 44 65 |\index{M|Stack!De|
|00003220| 63 6c 65 76 65 6c 28 29 | 7d 20 64 65 63 72 65 6d |clevel()|} decrem|
|00003230| 65 6e 74 73 20 74 68 65 | 20 76 61 6c 75 65 20 6f |ents the| value o|
|00003240| 66 0d 0a 6c 65 76 65 6c | 2e 20 49 74 20 69 73 20 |f..level|. It is |
|00003250| 63 61 6c 6c 65 64 20 62 | 79 20 44 65 63 52 65 74 |called b|y DecRet|
|00003260| 75 72 6e 28 29 2e 20 49 | 74 20 61 6c 73 6f 20 73 |urn(). I|t also s|
|00003270| 74 6f 70 73 0d 0a 74 68 | 65 20 70 72 6f 67 72 61 |tops..th|e progra|
|00003280| 6d 20 69 66 20 74 68 65 | 20 6e 65 73 74 69 6e 67 |m if the| nesting|
|00003290| 20 6c 65 76 65 6c 20 68 | 61 73 20 62 65 65 6e 20 | level h|as been |
|000032a0| 64 65 63 72 65 6d 65 6e | 74 65 64 20 74 6f 0d 0a |decremen|ted to..|
|000032b0| 7a 65 72 6f 2e 20 54 68 | 69 73 20 65 72 72 6f 72 |zero. Th|is error|
|000032c0| 20 69 6e 64 69 63 61 74 | 65 73 20 74 68 61 74 20 | indicat|es that |
|000032d0| 74 68 65 72 65 20 69 73 | 20 61 20 6d 69 73 6d 61 |there is| a misma|
|000032e0| 74 63 68 65 64 20 70 61 | 69 72 0d 0a 6f 66 20 63 |tched pa|ir..of c|
|000032f0| 61 6c 6c 73 20 74 6f 20 | 49 6e 63 6c 65 76 65 6c |alls to |Inclevel|
|00003300| 28 29 20 61 6e 64 20 44 | 65 63 52 65 74 75 72 6e |() and D|ecReturn|
|00003310| 28 29 2c 20 6f 72 20 49 | 6e 63 6c 65 76 65 6c 28 |(), or I|nclevel(|
|00003320| 29 20 61 6e 64 0d 0a 44 | 65 63 6c 65 76 65 6c 28 |) and..D|eclevel(|
|00003330| 29 2e 20 0d 0a 0d 0a 49 | 6e 63 6c 65 76 65 6c 28 |). ....I|nclevel(|
|00003340| 29 5c 69 6e 64 65 78 7b | 4d 53 74 61 63 6b 21 49 |)\index{|MStack!I|
|00003350| 6e 63 6c 65 76 65 6c 28 | 29 7d 20 69 6e 63 72 65 |nclevel(|)} incre|
|00003360| 6d 65 6e 74 73 20 74 68 | 65 20 66 75 6e 63 74 69 |ments th|e functi|
|00003370| 6f 6e 0d 0a 6e 65 73 74 | 69 6e 67 20 6c 65 76 65 |on..nest|ing leve|
|00003380| 6c 2e 20 55 73 75 61 6c | 6c 79 20 49 6e 63 6c 65 |l. Usual|ly Incle|
|00003390| 76 65 6c 28 29 20 69 73 | 20 63 61 6c 6c 65 64 20 |vel() is| called |
|000033a0| 77 68 65 6e 65 76 65 72 | 20 74 68 65 0d 0a 66 75 |whenever| the..fu|
|000033b0| 6e 63 74 69 6f 6e 20 77 | 69 6c 6c 20 75 73 65 20 |nction w|ill use |
|000033c0| 61 20 6d 61 74 72 69 78 | 20 61 73 73 69 67 6e 6d |a matrix| assignm|
|000033d0| 65 6e 74 2c 20 56 4d 61 | 74 72 69 78 3a 3a 6f 70 |ent, VMa|trix::op|
|000033e0| 65 72 61 74 6f 72 3d 28 | 29 2e 0d 0a 44 65 63 52 |erator=(|)...DecR|
|000033f0| 65 74 75 72 6e 28 29 20 | 63 61 6c 6c 73 20 44 65 |eturn() |calls De|
|00003400| 63 6c 65 76 65 6c 28 29 | 2c 20 73 6f 20 49 6e 63 |clevel()|, so Inc|
|00003410| 6c 65 76 65 6c 28 29 20 | 61 6e 64 20 44 65 63 52 |level() |and DecR|
|00003420| 65 74 75 72 6e 28 29 0d | 0a 73 68 6f 75 6c 64 20 |eturn().|.should |
|00003430| 62 65 20 75 73 65 64 20 | 69 6e 20 70 61 69 72 73 |be used |in pairs|
|00003440| 2e 20 20 46 75 6e 63 74 | 69 6f 6e 73 20 74 68 61 |. Funct|ions tha|
|00003450| 74 20 75 73 65 20 6d 61 | 74 72 69 78 20 61 73 73 |t use ma|trix ass|
|00003460| 69 67 6e 6d 65 6e 74 0d | 0a 6f 72 20 6d 61 74 72 |ignment.|.or matr|
|00003470| 69 78 20 63 6f 70 79 20 | 63 6f 6e 73 74 72 75 63 |ix copy |construc|
|00003480| 74 6f 72 73 20 64 6f 20 | 6e 6f 74 20 61 6c 77 61 |tors do |not alwa|
|00003490| 79 73 20 72 65 74 75 72 | 6e 20 6d 61 74 72 69 63 |ys retur|n matric|
|000034a0| 65 73 2e 20 49 6e 0d 0a | 74 68 69 73 20 63 61 73 |es. In..|this cas|
|000034b0| 65 20 79 6f 75 20 73 68 | 6f 75 6c 64 20 75 73 65 |e you sh|ould use|
|000034c0| 20 61 20 70 61 69 72 20 | 6f 66 20 49 6e 63 6c 65 | a pair |of Incle|
|000034d0| 76 65 6c 2d 44 65 63 6c | 65 76 65 6c 20 63 61 6c |vel-Decl|evel cal|
|000034e0| 6c 73 20 74 6f 0d 0a 63 | 6f 6e 74 72 6f 6c 20 74 |ls to..c|ontrol t|
|000034f0| 68 65 20 73 74 61 63 6b | 2e 20 20 0d 0a 0d 0a 54 |he stack|. ....T|
|00003500| 68 65 20 63 6f 64 65 20 | 66 6f 72 20 44 65 63 52 |he code |for DecR|
|00003510| 65 74 75 72 6e 28 29 20 | 61 6e 64 20 52 65 74 75 |eturn() |and Retu|
|00003520| 72 6e 4d 61 74 28 29 20 | 69 73 0d 0a 67 69 76 65 |rnMat() |is..give|
|00003530| 6e 20 62 65 6c 6f 77 20 | 62 79 0d 0a 5c 62 65 67 |n below |by..\beg|
|00003540| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 0a 20 20 |in{verba|tim}.. |
|00003550| 20 20 56 4d 61 74 72 69 | 78 20 26 44 65 63 52 65 | VMatri|x &DecRe|
|00003560| 74 75 72 6e 28 20 76 6f | 69 64 20 29 7b 0d 0a 20 |turn( vo|id ){.. |
|00003570| 20 20 20 20 20 20 20 20 | 44 65 63 6c 65 76 65 6c | |Declevel|
|00003580| 28 29 3b 0d 0a 20 20 20 | 20 20 20 20 20 20 6e 65 |();.. | ne|
|00003590| 78 74 2d 3e 6c 65 76 65 | 6c 20 3d 20 6c 65 76 65 |xt->leve|l = leve|
|000035a0| 6c 3b 0d 0a 20 20 20 20 | 20 20 20 20 20 72 65 74 |l;.. | ret|
|000035b0| 75 72 6e 20 2a 20 28 28 | 56 4d 61 74 72 69 78 20 |urn * ((|VMatrix |
|000035c0| 2a 29 20 74 68 69 73 2d | 3e 6e 65 78 74 29 3b 0d |*) this-|>next);.|
|000035d0| 0a 20 20 20 20 20 7d 0d | 0a 20 20 20 20 56 4d 61 |. }.|. VMa|
|000035e0| 74 72 69 78 20 26 52 65 | 74 75 72 6e 4d 61 74 28 |trix &Re|turnMat(|
|000035f0| 20 76 6f 69 64 20 29 7b | 0d 0a 20 20 20 20 20 20 | void ){|.. |
|00003600| 20 20 20 6e 65 78 74 2d | 3e 6c 65 76 65 6c 20 3d | next-|>level =|
|00003610| 20 6c 65 76 65 6c 3b 0d | 0a 20 20 20 20 20 20 20 | level;.|. |
|00003620| 20 20 72 65 74 75 72 6e | 20 2a 20 28 28 56 4d 61 | return| * ((VMa|
|00003630| 74 72 69 78 20 2a 29 20 | 74 68 69 73 2d 3e 6e 65 |trix *) |this->ne|
|00003640| 78 74 29 3b 0d 0a 20 20 | 20 20 20 7d 0d 0a 5c 65 |xt);.. | }..\e|
|00003650| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 0d 0a 54 68 |nd{verba|tim}..Th|
|00003660| 65 20 74 77 6f 20 66 75 | 6e 63 74 69 6f 6e 73 20 |e two fu|nctions |
|00003670| 70 65 72 66 6f 72 6d 20 | 73 69 6d 69 6c 61 72 20 |perform |similar |
|00003680| 66 75 6e 63 74 69 6f 6e | 73 20 65 78 63 65 70 74 |function|s except|
|00003690| 20 74 68 61 74 0d 0a 44 | 65 63 52 65 74 75 72 6e | that..D|ecReturn|
|000036a0| 28 29 20 63 61 6c 6c 73 | 20 44 65 63 6c 65 76 65 |() calls| Decleve|
|000036b0| 6c 28 29 2e 20 54 68 65 | 79 20 62 6f 74 68 20 61 |l(). The|y both a|
|000036c0| 72 65 20 63 61 6c 6c 65 | 64 20 66 72 6f 6d 0d 0a |re calle|d from..|
|000036d0| 44 69 73 70 61 74 63 68 | 2c 20 73 6f 20 2a 74 68 |Dispatch|, so *th|
|000036e0| 69 73 20 69 73 20 61 63 | 74 75 61 6c 6c 79 20 44 |is is ac|tually D|
|000036f0| 69 73 70 61 74 63 68 2e | 20 54 68 65 20 66 75 6e |ispatch.| The fun|
|00003700| 63 74 69 6f 6e 73 20 73 | 65 74 20 6c 65 76 65 6c |ctions s|et level|
|00003710| 0d 0a 69 6e 20 6e 65 78 | 74 20 74 6f 20 44 69 73 |..in nex|t to Dis|
|00003720| 70 61 74 63 68 2d 24 3e | 24 6c 65 76 65 6c 2e 20 |patch-$>|$level. |
|00003730| 59 6f 75 20 75 73 65 20 | 52 65 74 75 72 6e 4d 61 |You use |ReturnMa|
|00003740| 74 28 29 20 69 66 20 79 | 6f 75 20 64 69 64 20 6e |t() if y|ou did n|
|00003750| 6f 74 0d 0a 6e 65 65 64 | 20 6d 61 74 72 69 78 20 |ot..need| matrix |
|00003760| 61 73 73 69 67 6e 6d 65 | 6e 74 20 69 6e 20 61 20 |assignme|nt in a |
|00003770| 66 75 6e 63 74 69 6f 6e | 2c 20 61 6e 64 20 68 65 |function|, and he|
|00003780| 6e 63 65 20 64 69 64 20 | 6e 6f 74 20 63 61 6c 6c |nce did |not call|
|00003790| 0d 0a 49 6e 63 6c 65 76 | 65 6c 28 29 20 61 74 20 |..Inclev|el() at |
|000037a0| 74 68 65 20 74 6f 70 2e | 20 59 6f 75 20 75 73 65 |the top.| You use|
|000037b0| 20 44 65 63 52 65 74 75 | 72 6e 28 29 20 69 66 20 | DecRetu|rn() if |
|000037c0| 79 6f 75 20 6e 65 65 64 | 65 64 20 74 6f 20 75 73 |you need|ed to us|
|000037d0| 65 0d 0a 6d 61 74 72 69 | 78 20 61 73 73 69 67 6e |e..matri|x assign|
|000037e0| 6d 65 6e 74 20 68 65 6e | 63 65 20 63 61 6c 6c 65 |ment hen|ce calle|
|000037f0| 64 20 49 6e 63 6c 65 76 | 65 6c 28 29 20 61 74 20 |d Inclev|el() at |
|00003800| 74 68 65 20 74 6f 70 2e | 20 54 68 65 20 72 65 74 |the top.| The ret|
|00003810| 75 72 6e 0d 0a 73 74 61 | 74 6d 65 6e 74 20 72 65 |urn..sta|tment re|
|00003820| 63 61 73 74 73 20 44 69 | 73 70 61 74 63 68 20 61 |casts Di|spatch a|
|00003830| 73 20 61 20 56 4d 61 74 | 72 69 78 20 70 6f 69 6e |s a VMat|rix poin|
|00003840| 74 65 72 2c 20 61 6e 64 | 20 72 65 74 75 72 6e 73 |ter, and| returns|
|00003850| 20 74 68 65 0d 0a 6d 61 | 74 72 69 78 20 72 65 66 | the..ma|trix ref|
|00003860| 65 72 65 6e 63 65 20 73 | 74 6f 72 65 64 20 69 6e |erence s|tored in|
|00003870| 20 6e 65 78 74 2e 0d 0a | 0d 0a 43 6c 65 61 6e 73 | next...|..Cleans|
|00003880| 74 61 63 6b 28 29 5c 69 | 6e 64 65 78 7b 4d 53 74 |tack()\i|ndex{MSt|
|00003890| 61 63 6b 21 43 6c 65 61 | 6e 73 74 61 63 6b 28 29 |ack!Clea|nstack()|
|000038a0| 7d 20 69 73 20 73 68 6f | 72 74 3a 0d 0a 5c 62 65 |} is sho|rt:..\be|
|000038b0| 67 69 6e 7b 76 65 72 62 | 61 74 69 6d 7d 0d 0a 20 |gin{verb|atim}.. |
|000038c0| 20 77 68 69 6c 65 28 20 | 44 69 73 70 61 74 63 68 | while( |Dispatch|
|000038d0| 2d 3e 6e 65 78 74 2d 3e | 6c 65 76 65 6c 20 3e 3d |->next->|level >=|
|000038e0| 20 44 69 73 70 61 74 63 | 68 2d 3e 6c 65 76 65 6c | Dispatc|h->level|
|000038f0| 0d 0a 20 20 20 20 20 20 | 20 20 20 26 26 20 44 69 |.. | && Di|
|00003900| 73 70 61 74 63 68 2d 3e | 6e 65 78 74 2d 3e 6e 65 |spatch->|next->ne|
|00003910| 78 74 29 20 44 69 73 70 | 61 74 63 68 2d 3e 50 6f |xt) Disp|atch->Po|
|00003920| 70 28 29 3b 0d 0a 5c 65 | 6e 64 7b 76 65 72 62 61 |p();..\e|nd{verba|
|00003930| 74 69 6d 7d 0d 0a 49 74 | 20 63 61 6c 6c 73 20 50 |tim}..It| calls P|
|00003940| 6f 70 28 29 20 77 68 69 | 6c 65 20 74 68 65 20 6e |op() whi|le the n|
|00003950| 65 78 74 20 73 74 61 63 | 6b 20 6d 61 74 72 69 78 |ext stac|k matrix|
|00003960| 20 68 61 73 20 61 20 6c | 65 76 65 6c 20 61 74 20 | has a l|evel at |
|00003970| 6c 65 61 73 74 0d 0a 61 | 73 20 6c 61 72 67 65 20 |least..a|s large |
|00003980| 61 73 20 44 69 73 70 61 | 74 63 68 2d 24 3e 24 6c |as Dispa|tch-$>$l|
|00003990| 65 76 65 6c 2e 20 49 74 | 20 61 6c 73 6f 20 73 74 |evel. It| also st|
|000039a0| 6f 70 73 20 74 68 65 20 | 70 6f 70 70 69 6e 67 20 |ops the |popping |
|000039b0| 77 68 65 6e 0d 0a 74 68 | 65 72 65 20 69 73 20 6f |when..th|ere is o|
|000039c0| 6e 6c 79 20 6f 6e 65 20 | 6d 61 74 72 69 78 20 6c |nly one |matrix l|
|000039d0| 65 66 74 20 6f 6e 20 74 | 68 65 20 73 74 61 63 6b |eft on t|he stack|
|000039e0| 20 77 68 69 63 68 20 69 | 73 20 75 73 65 66 75 6c | which i|s useful|
|000039f0| 20 77 68 65 6e 0d 0a 74 | 68 65 72 65 20 61 72 65 | when..t|here are|
|00003a00| 20 70 72 6f 62 6c 65 6d | 73 20 69 6e 20 74 68 65 | problem|s in the|
|00003a10| 20 70 72 6f 67 72 61 6d | 2e 20 54 68 69 73 20 63 | program|. This c|
|00003a20| 6c 65 61 72 73 20 74 68 | 65 20 6c 6f 63 61 6c 20 |lears th|e local |
|00003a30| 73 74 61 63 6b 2e 0d 0a | 52 65 63 61 6c 6c 20 74 |stack...|Recall t|
|00003a40| 68 61 74 20 43 6c 65 61 | 6e 73 74 61 63 6b 28 29 |hat Clea|nstack()|
|00003a50| 20 69 73 20 63 61 6c 6c | 65 64 20 62 79 20 56 4d | is call|ed by VM|
|00003a60| 61 74 72 69 78 3a 3a 6f | 70 65 72 61 74 6f 72 3d |atrix::o|perator=|
|00003a70| 28 29 2e 0d 0a 54 68 65 | 20 65 71 75 61 6c 73 20 |()...The| equals |
|00003a80| 6f 70 65 72 61 74 6f 72 | 20 72 65 70 6c 61 63 65 |operator| replace|
|00003a90| 73 20 69 74 73 20 6c 65 | 66 74 20 6f 70 65 72 61 |s its le|ft opera|
|00003aa0| 6e 64 20 62 79 20 74 68 | 65 20 72 69 67 68 74 0d |nd by th|e right.|
|00003ab0| 0a 62 65 66 6f 72 65 20 | 63 61 6c 6c 69 6e 67 20 |.before |calling |
|00003ac0| 43 6c 65 61 6e 73 74 61 | 63 6b 28 29 2e 20 54 68 |Cleansta|ck(). Th|
|00003ad0| 65 20 6c 65 66 74 20 6f | 70 65 72 61 6e 64 20 69 |e left o|perand i|
|00003ae0| 73 20 6e 6f 74 20 69 6e | 20 74 68 65 0d 0a 73 74 |s not in| the..st|
|00003af0| 61 63 6b 2c 20 73 6f 20 | 69 74 20 69 73 20 6e 6f |ack, so |it is no|
|00003b00| 74 20 64 65 6c 65 74 65 | 64 20 62 79 20 50 6f 70 |t delete|d by Pop|
|00003b10| 28 29 2e 20 0d 0a 0d 0a | 54 68 65 20 63 6f 70 79 |(). ....|The copy|
|00003b20| 20 63 6f 6e 73 74 72 75 | 63 74 6f 72 5c 69 6e 64 | constru|ctor\ind|
|00003b30| 65 78 7b 56 4d 61 74 72 | 69 78 21 43 6f 70 79 20 |ex{VMatr|ix!Copy |
|00003b40| 63 6f 6e 73 74 72 75 63 | 74 6f 72 7d 0d 0a 5c 69 |construc|tor}..\i|
|00003b50| 6e 64 65 78 7b 4d 53 74 | 61 63 6b 21 56 4d 61 74 |ndex{MSt|ack!VMat|
|00003b60| 72 69 78 20 43 6f 70 79 | 20 43 6f 6e 73 74 72 75 |rix Copy| Constru|
|00003b70| 63 74 6f 72 7d 20 20 63 | 61 6c 6c 73 0d 0a 43 6c |ctor} c|alls..Cl|
|00003b80| 65 61 6e 73 74 61 63 6b | 28 29 20 73 6f 20 69 74 |eanstack|() so it|
|00003b90| 20 61 6c 73 6f 20 65 6c | 69 6d 69 6e 61 74 65 73 | also el|iminates|
|00003ba0| 20 74 65 6d 70 6f 72 61 | 72 79 20 6d 61 74 72 69 | tempora|ry matri|
|00003bb0| 63 65 73 2e 0d 0a 54 68 | 65 72 65 66 6f 72 65 2c |ces...Th|erefore,|
|00003bc0| 20 79 6f 75 20 73 68 6f | 75 6c 64 20 63 61 6c 6c | you sho|uld call|
|00003bd0| 20 49 6e 63 6c 65 76 65 | 6c 28 29 20 61 6e 64 20 | Incleve|l() and |
|00003be0| 44 65 63 6c 65 76 65 6c | 28 29 20 69 66 20 79 6f |Declevel|() if yo|
|00003bf0| 75 20 69 6e 74 65 6e 64 | 0d 0a 74 6f 20 75 73 65 |u intend|..to use|
|00003c00| 20 74 68 65 20 63 6f 70 | 79 20 63 6f 6e 73 74 72 | the cop|y constr|
|00003c10| 75 63 74 6f 72 73 2e 0d | 0a 20 0d 0a 59 6f 75 20 |uctors..|. ..You |
|00003c20| 6d 61 79 20 77 69 73 68 | 20 74 6f 20 63 61 6c 6c |may wish| to call|
|00003c30| 20 43 6c 65 61 6e 73 74 | 61 63 6b 28 29 20 6f 63 | Cleanst|ack() oc|
|00003c40| 63 61 73 69 6f 6e 61 6c | 6c 79 20 69 66 20 79 6f |casional|ly if yo|
|00003c50| 75 20 61 72 65 20 69 6e | 20 74 68 65 0d 0a 68 61 |u are in| the..ha|
|00003c60| 62 69 74 20 6f 66 20 75 | 73 69 6e 67 20 73 74 61 |bit of u|sing sta|
|00003c70| 74 65 6d 65 6e 74 73 20 | 73 75 63 68 20 61 73 0d |tements |such as.|
|00003c80| 0a 5c 76 65 72 62 2b 28 | 54 72 61 6e 28 58 29 2a |.\verb+(|Tran(X)*|
|00003c90| 58 29 2e 44 69 73 70 61 | 6c 61 79 4d 61 74 28 29 |X).Dispa|layMat()|
|00003ca0| 3b 2b 2e 20 5c 66 6f 6f | 74 6e 6f 74 65 7b 42 79 |;+. \foo|tnote{By|
|00003cb0| 20 74 68 65 20 77 61 79 | 2c 20 6a 75 73 74 20 77 | the way|, just w|
|00003cc0| 68 61 74 20 69 73 0d 0a | 74 68 69 73 2c 20 61 20 |hat is..|this, a |
|00003cd0| 73 74 61 74 65 6d 65 6e | 74 20 6f 72 20 61 20 66 |statemen|t or a f|
|00003ce0| 75 6e 63 74 69 6f 6e 20 | 63 61 6c 6c 3f 7d 20 54 |unction |call?} T|
|00003cf0| 68 65 73 65 0d 0a 73 74 | 61 74 65 6d 65 6e 74 2d |hese..st|atement-|
|00003d00| 2d 66 75 6e 63 74 69 6f | 6e 2d 2d 63 61 6c 6c 73 |-functio|n--calls|
|00003d10| 20 6c 65 61 76 65 20 6d | 61 74 72 69 63 65 73 20 | leave m|atrices |
|00003d20| 6f 6e 20 74 68 65 0d 0a | 73 74 61 63 6b 20 77 68 |on the..|stack wh|
|00003d30| 69 63 68 20 61 72 65 20 | 72 65 6d 6f 76 65 64 20 |ich are |removed |
|00003d40| 61 75 74 6f 6d 61 74 69 | 63 61 6c 6c 79 20 64 75 |automati|cally du|
|00003d50| 72 69 6e 67 20 61 20 6d | 61 74 72 69 78 0d 0a 61 |ring a m|atrix..a|
|00003d60| 73 73 69 67 6e 6d 65 6e | 74 2c 20 61 20 63 6f 70 |ssignmen|t, a cop|
|00003d70| 79 20 63 6f 6e 73 74 72 | 75 63 74 6f 72 2c 20 6f |y constr|uctor, o|
|00003d80| 72 20 62 79 20 61 6e 20 | 65 78 70 6c 69 63 69 74 |r by an |explicit|
|00003d90| 20 63 61 6c 6c 20 74 6f | 0d 0a 43 6c 65 61 6e 73 | call to|..Cleans|
|00003da0| 74 61 63 6b 28 29 2e 0d | 0a 0d 0a 50 72 69 6e 74 |tack()..|...Print|
|00003db0| 53 74 61 63 6b 28 29 5c | 69 6e 64 65 78 7b 4d 53 |Stack()\|index{MS|
|00003dc0| 74 61 63 6b 21 50 72 69 | 6e 74 53 74 61 63 6b 28 |tack!Pri|ntStack(|
|00003dd0| 29 7d 20 74 72 61 76 65 | 72 73 65 73 20 74 68 65 |)} trave|rses the|
|00003de0| 0d 0a 73 74 61 63 6b 2e | 20 49 74 20 72 65 70 6f |..stack.| It repo|
|00003df0| 72 74 73 20 74 68 65 20 | 73 74 61 63 6b 6c 6f 63 |rts the |stackloc|
|00003e00| 2c 20 6c 65 76 65 6c 2c | 20 72 2c 20 63 20 61 6e |, level,| r, c an|
|00003e10| 64 20 6e 61 6d 65 20 66 | 6f 72 0d 0a 65 61 63 68 |d name f|or..each|
|00003e20| 20 6d 61 74 72 69 78 20 | 69 6e 20 74 68 65 20 73 | matrix |in the s|
|00003e30| 74 61 63 6b 2e | |tack. | |
+--------+-------------------------+-------------------------+--------+--------+