home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / yamp / vdoub.tex < prev    next >
LaTeX Document  |  1992-06-08  |  8.3 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
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 data 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 56 69 72 74 75 61 6c |\chapter|{Virtual|
|00000010| 20 56 65 63 74 6f 72 20 | 6f 66 20 44 6f 75 62 6c | Vector |of Doubl|
|00000020| 65 73 7d 0d 0a 0d 0a 54 | 68 65 20 76 69 72 74 75 |es}....T|he virtu|
|00000030| 61 6c 20 6d 61 74 72 69 | 78 20 63 6c 61 73 73 20 |al matri|x class |
|00000040| 69 73 20 64 65 72 69 76 | 65 64 20 66 72 6f 6d 20 |is deriv|ed from |
|00000050| 61 20 63 6c 61 73 73 20 | 6f 66 20 61 0d 0a 76 65 |a class |of a..ve|
|00000060| 63 74 6f 72 20 6f 66 20 | 64 6f 75 62 6c 65 73 20 |ctor of |doubles |
|00000070| 73 74 6f 72 65 64 20 69 | 6e 20 74 68 65 20 76 69 |stored i|n the vi|
|00000080| 72 74 75 61 6c 20 6d 65 | 6d 6f 72 79 20 73 79 73 |rtual me|mory sys|
|00000090| 74 65 6d 2e 20 54 68 65 | 0d 0a 76 69 72 74 75 61 |tem. The|..virtua|
|000000a0| 6c 20 76 65 63 74 6f 72 | 20 67 69 76 65 73 20 74 |l vector| gives t|
|000000b0| 68 65 20 6d 61 74 72 69 | 78 20 63 6c 61 73 73 20 |he matri|x class |
|000000c0| 61 63 63 65 73 73 20 74 | 6f 20 74 68 65 20 76 69 |access t|o the vi|
|000000d0| 72 74 75 61 6c 0d 0a 6d | 65 6d 6f 72 79 2e 20 48 |rtual..m|emory. H|
|000000e0| 6f 6c 75 62 5c 63 69 74 | 65 7b 48 6f 3a 70 72 7d |olub\cit|e{Ho:pr}|
|000000f0| 20 64 65 76 65 6c 6f 70 | 65 64 20 61 20 63 6c 61 | develop|ed a cla|
|00000100| 73 73 20 6f 66 20 69 6e | 74 65 67 65 72 0d 0a 76 |ss of in|teger..v|
|00000110| 65 63 74 6f 72 73 20 77 | 69 74 68 20 61 20 73 65 |ectors w|ith a se|
|00000120| 74 20 6f 66 20 6f 76 65 | 72 6c 6f 61 64 65 64 20 |t of ove|rloaded |
|00000130| 6f 70 65 72 61 74 6f 72 | 73 2e 20 48 65 20 63 72 |operator|s. He cr|
|00000140| 65 61 74 65 64 20 74 68 | 65 0d 0a 63 6c 61 73 73 |eated th|e..class|
|00000150| 20 74 6f 20 65 61 73 65 | 20 61 63 63 65 73 73 20 | to ease| access |
|00000160| 74 6f 20 74 68 65 20 76 | 6d 6d 2c 20 61 6e 64 20 |to the v|mm, and |
|00000170| 64 65 6d 6f 6e 73 74 72 | 61 74 65 20 73 65 76 65 |demonstr|ate seve|
|00000180| 72 61 6c 0d 0a 61 73 70 | 65 63 74 73 20 6f 66 20 |ral..asp|ects of |
|00000190| 75 73 69 6e 67 20 63 6c | 61 73 73 65 73 2e 20 48 |using cl|asses. H|
|000001a0| 65 72 65 2c 20 74 68 65 | 20 69 6e 74 65 67 65 72 |ere, the| integer|
|000001b0| 20 63 6c 61 73 73 20 77 | 61 73 0d 0a 72 65 77 72 | class w|as..rewr|
|000001c0| 69 74 74 65 6e 20 66 6f | 72 20 64 6f 75 62 6c 65 |itten fo|r double|
|000001d0| 73 2c 20 61 6e 64 20 74 | 68 65 20 6f 70 65 72 61 |s, and t|he opera|
|000001e0| 74 6f 72 73 20 77 65 72 | 65 20 73 74 72 69 70 70 |tors wer|e stripp|
|000001f0| 65 64 20 69 6e 0d 0a 66 | 61 76 6f 72 20 6f 66 20 |ed in..f|avor of |
|00000200| 75 73 69 6e 67 20 74 68 | 65 6d 20 6f 6e 20 74 68 |using th|em on th|
|00000210| 65 20 6d 61 74 72 69 63 | 65 73 2e 0d 0a 0d 0a 41 |e matric|es.....A|
|00000220| 67 61 69 6e 2c 20 74 68 | 65 20 76 69 72 74 75 61 |gain, th|e virtua|
|00000230| 6c 20 76 65 63 74 6f 72 | 20 73 68 6f 75 6c 64 20 |l vector| should |
|00000240| 62 65 20 63 6f 6e 73 69 | 64 65 72 65 64 20 61 6e |be consi|dered an|
|00000250| 6f 74 68 65 72 0d 0a 69 | 6e 74 65 72 6d 65 64 69 |other..i|ntermedi|
|00000260| 61 74 65 20 73 74 65 70 | 20 69 6e 20 63 72 65 61 |ate step| in crea|
|00000270| 74 69 6e 67 20 74 68 65 | 20 76 69 72 74 75 61 6c |ting the| virtual|
|00000280| 20 6d 61 74 72 69 78 20 | 63 6c 61 73 73 2e 20 49 | matrix |class. I|
|00000290| 74 20 69 73 0d 0a 6e 6f | 74 20 6e 65 65 64 65 64 |t is..no|t needed|
|000002a0| 20 69 6e 20 74 68 65 20 | 69 6e 2d 72 61 6d 20 76 | in the |in-ram v|
|000002b0| 65 72 73 69 6f 6e 2c 20 | 73 69 6e 63 65 20 6d 61 |ersion, |since ma|
|000002c0| 74 72 69 63 65 73 20 61 | 72 65 20 61 6c 6c 6f 63 |trices a|re alloc|
|000002d0| 61 74 65 64 0d 0a 6f 6e | 20 74 68 65 20 68 65 61 |ated..on| the hea|
|000002e0| 70 2e 20 49 6e 73 74 65 | 61 64 20 61 20 73 74 72 |p. Inste|ad a str|
|000002f0| 75 63 74 75 72 65 20 69 | 73 20 75 73 65 64 20 74 |ucture i|s used t|
|00000300| 6f 20 73 74 6f 72 65 20 | 61 20 76 65 63 74 6f 72 |o store |a vector|
|00000310| 0d 0a 61 6c 6c 6f 63 61 | 74 65 64 20 62 79 20 63 |..alloca|ted by c|
|00000320| 61 6c 6c 6f 63 2c 20 61 | 6e 64 20 74 68 65 20 6e |alloc, a|nd the n|
|00000330| 75 6d 62 65 72 20 6f 66 | 20 72 65 66 65 72 65 6e |umber of| referen|
|00000340| 63 65 73 20 74 6f 20 74 | 68 65 0d 0a 73 74 72 75 |ces to t|he..stru|
|00000350| 63 74 75 72 65 2e 20 54 | 68 69 73 20 77 69 6c 6c |cture. T|his will|
|00000360| 20 62 65 20 65 78 70 6c | 61 6e 65 64 20 69 6e 20 | be expl|aned in |
|00000370| 6d 6f 72 65 20 64 65 74 | 61 69 6c 20 69 6e 20 74 |more det|ail in t|
|00000380| 68 65 20 63 68 61 70 74 | 65 72 0d 0a 6f 6e 20 74 |he chapt|er..on t|
|00000390| 68 65 20 73 74 61 63 6b | 2e 0d 0a 0d 0a 5c 73 65 |he stack|.....\se|
|000003a0| 63 74 69 6f 6e 7b 76 64 | 6f 75 62 7d 0d 0a 54 68 |ction{vd|oub}..Th|
|000003b0| 65 20 76 69 72 74 75 61 | 6c 20 76 65 63 74 6f 72 |e virtua|l vector|
|000003c0| 20 6f 66 20 64 6f 75 62 | 6c 65 73 5c 69 6e 64 65 | of doub|les\inde|
|000003d0| 78 7b 76 64 6f 75 62 20 | 7d 20 69 73 20 64 65 63 |x{vdoub |} is dec|
|000003e0| 6c 61 72 65 64 20 69 6e | 0d 0a 74 68 65 20 66 6f |lared in|..the fo|
|000003f0| 6c 6c 6f 77 69 6e 67 20 | 63 6c 61 73 73 20 73 74 |llowing |class st|
|00000400| 61 74 65 6d 65 6e 74 0d | 0a 0d 0a 5c 62 65 67 69 |atement.|...\begi|
|00000410| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0d 0a 63 6c 61 |n{verbat|im}..cla|
|00000420| 73 73 20 76 64 6f 75 62 | 7b 0d 0a 0d 0a 20 20 70 |ss vdoub|{.... p|
|00000430| 72 6f 74 65 63 74 65 64 | 3a 0d 0a 20 20 0d 0a 20 |rotected|:.. .. |
|00000440| 20 20 20 75 6e 73 69 67 | 6e 65 64 20 73 69 67 6e | unsig|ned sign|
|00000450| 61 74 75 72 65 3b 2f 2f | 20 67 61 72 62 61 67 65 |ature;//| garbage|
|00000460| 20 66 6c 61 67 3b 0d 0a | 20 20 20 20 68 64 72 20 | flag;..| hdr |
|00000470| 2a 68 64 72 3b 20 20 20 | 20 20 20 20 20 20 20 2f |*hdr; | /|
|00000480| 2f 20 76 69 72 74 75 61 | 6c 20 6d 65 6d 6f 72 79 |/ virtua|l memory|
|00000490| 20 68 61 6e 64 6c 65 0d | 0a 20 20 20 20 64 6f 75 | handle.|. dou|
|000004a0| 62 6c 65 20 2a 63 75 72 | 5f 65 6c 65 3b 20 20 20 |ble *cur|_ele; |
|000004b0| 2f 2f 20 63 75 72 72 65 | 6e 74 20 65 6c 65 6d 65 |// curre|nt eleme|
|000004c0| 6e 74 0d 0a 20 20 20 20 | 6c 6f 6e 67 20 20 63 75 |nt.. |long cu|
|000004d0| 72 5f 69 6e 64 65 78 3b | 20 20 20 2f 2f 20 63 75 |r_index;| // cu|
|000004e0| 72 72 65 6e 74 20 69 6e | 64 65 78 0d 0a 20 20 20 |rrent in|dex.. |
|000004f0| 20 2f 2f 73 74 61 74 69 | 63 20 69 6e 74 20 6e 6f | //stati|c int no|
|00000500| 62 6a 3b 0d 0a 0d 0a 20 | 20 20 20 66 72 69 65 6e |bj;.... | frien|
|00000510| 64 20 64 6f 75 62 6c 65 | 20 76 61 6c 28 20 76 64 |d double| val( vd|
|00000520| 6f 75 62 20 26 76 29 3b | 0d 0a 20 20 0d 0a 20 20 |oub &v);|.. .. |
|00000530| 70 75 62 6c 69 63 3a 0d | 0a 20 20 0d 0a 20 20 20 |public:.|. .. |
|00000540| 20 69 6e 74 20 47 61 72 | 62 61 67 65 28 20 76 6f | int Gar|bage( vo|
|00000550| 69 64 20 29 7b 20 72 65 | 74 75 72 6e 20 20 21 28 |id ){ re|turn !(|
|00000560| 20 73 69 67 6e 61 74 75 | 72 65 20 3d 3d 20 53 49 | signatu|re == SI|
|00000570| 47 4e 41 54 55 52 45 20 | 29 3b 20 7d 0d 0a 0d 0a |GNATURE |); }....|
|00000580| 20 20 20 20 76 64 6f 75 | 62 20 28 20 6c 6f 6e 67 | vdou|b ( long|
|00000590| 20 61 72 72 61 79 5f 73 | 69 7a 65 20 29 3b 0d 0a | array_s|ize );..|
|000005a0| 20 20 20 20 76 64 6f 75 | 62 20 28 20 76 6f 69 64 | vdou|b ( void|
|000005b0| 20 29 3b 0d 0a 20 20 20 | 20 76 64 6f 75 62 20 28 | );.. | vdoub (|
|000005c0| 20 76 64 6f 75 62 20 26 | 73 72 63 20 29 3b 0d 0a | vdoub &|src );..|
|000005d0| 20 20 20 20 7e 76 64 6f | 75 62 28 20 76 6f 69 64 | ~vdo|ub( void|
|000005e0| 20 29 3b 0d 0a 0d 0a 20 | 20 20 20 64 6f 75 62 6c | );.... | doubl|
|000005f0| 65 20 76 28 20 6c 6f 6e | 67 20 69 6e 64 65 78 20 |e v( lon|g index |
|00000600| 29 3b 20 20 20 20 20 20 | 20 20 20 20 2f 2f 20 67 |); | // g|
|00000610| 65 74 20 76 61 6c 75 65 | 0d 0a 20 20 20 20 76 64 |et value|.. vd|
|00000620| 6f 75 62 26 20 6f 70 65 | 72 61 74 6f 72 5b 5d 28 |oub& ope|rator[](|
|00000630| 20 6c 6f 6e 67 20 69 6e | 64 65 78 20 29 3b 20 2f | long in|dex ); /|
|00000640| 2f 20 73 74 6f 72 65 20 | 76 61 6c 75 65 0d 0a 20 |/ store |value.. |
|00000650| 20 20 20 64 6f 75 62 6c | 65 20 6f 70 65 72 61 74 | doubl|e operat|
|00000660| 6f 72 20 3d 20 28 20 64 | 6f 75 62 6c 65 20 64 20 |or = ( d|ouble d |
|00000670| 29 3b 0d 0a 20 20 20 20 | 64 6f 75 62 6c 65 20 6f |);.. |double o|
|00000680| 70 65 72 61 74 6f 72 20 | 3d 20 28 20 76 64 6f 75 |perator |= ( vdou|
|00000690| 62 20 26 76 20 29 3b 0d | 0a 7d 3b 0d 0a 5c 65 6e |b &v );.|.};..\en|
|000006a0| 64 7b 76 65 72 62 61 74 | 69 6d 7d 0d 0a 0d 0a 4e |d{verbat|im}....N|
|000006b0| 6f 74 65 20 74 68 61 74 | 20 74 68 65 20 61 63 63 |ote that| the acc|
|000006c0| 65 73 73 20 74 6f 20 74 | 68 65 20 76 6d 6d 20 69 |ess to t|he vmm i|
|000006d0| 73 20 69 6e 20 61 20 70 | 72 6f 74 65 63 74 65 64 |s in a p|rotected|
|000006e0| 20 73 65 63 74 69 6f 6e | 0d 0a 6f 66 20 74 68 65 | section|..of the|
|000006f0| 20 64 65 66 69 6e 69 74 | 69 6f 6e 2e 20 54 68 65 | definit|ion. The|
|00000700| 20 6d 61 74 72 69 78 20 | 63 6c 61 73 73 20 6e 65 | matrix |class ne|
|00000710| 65 64 73 20 61 63 63 65 | 73 73 20 74 6f 20 73 6f |eds acce|ss to so|
|00000720| 6d 65 20 6f 66 0d 0a 74 | 68 65 73 65 20 65 6c 65 |me of..t|hese ele|
|00000730| 6d 65 6e 74 73 2e 20 0d | 0a 0d 0a 5c 73 75 62 73 |ments. .|...\subs|
|00000740| 65 63 74 69 6f 6e 7b 50 | 72 6f 74 65 63 74 65 64 |ection{P|rotected|
|00000750| 20 50 61 72 74 20 6f 66 | 20 61 20 76 64 6f 75 62 | Part of| a vdoub|
|00000760| 7d 0d 0a 54 68 65 20 73 | 69 67 6e 61 74 75 72 65 |}..The s|ignature|
|00000770| 20 69 73 20 61 20 67 61 | 72 62 61 67 65 20 66 6c | is a ga|rbage fl|
|00000780| 61 67 2e 20 49 74 20 69 | 73 20 73 65 74 20 74 6f |ag. It i|s set to|
|00000790| 20 7a 65 72 6f 20 77 68 | 65 6e 20 74 68 65 0d 0a | zero wh|en the..|
|000007a0| 76 65 63 74 6f 72 20 69 | 73 20 64 65 6c 65 74 65 |vector i|s delete|
|000007b0| 64 2e 20 49 74 20 61 6c | 73 6f 20 73 65 72 76 65 |d. It al|so serve|
|000007c0| 73 20 61 73 20 61 20 63 | 68 65 63 6b 20 66 6f 72 |s as a c|heck for|
|000007d0| 20 74 68 65 20 66 72 6f | 6e 74 20 6f 66 0d 0a 74 | the fro|nt of..t|
|000007e0| 68 65 20 63 6c 61 73 73 | 20 62 65 69 6e 67 20 6f |he class| being o|
|000007f0| 76 65 72 77 72 69 74 74 | 65 6e 20 62 79 20 72 6f |verwritt|en by ro|
|00000800| 67 75 65 20 66 75 6e 63 | 74 69 6f 6e 73 2e 20 54 |gue func|tions. T|
|00000810| 68 65 20 68 64 72 20 69 | 73 0d 0a 61 20 70 6f 69 |he hdr i|s..a poi|
|00000820| 6e 74 65 72 20 74 6f 20 | 61 20 76 6d 6d 20 68 65 |nter to |a vmm he|
|00000830| 61 64 65 72 20 63 72 65 | 61 74 65 64 20 62 79 20 |ader cre|ated by |
|00000840| 76 6d 61 6c 6c 6f 63 2e | 20 0d 0a 0d 0a 54 68 65 |vmalloc.| ....The|
|00000850| 20 63 75 72 5c 5f 65 6c | 65 20 69 73 20 61 20 70 | cur\_el|e is a p|
|00000860| 6f 69 6e 74 65 72 20 74 | 6f 20 74 68 65 20 63 75 |ointer t|o the cu|
|00000870| 72 72 65 6e 74 20 65 6c | 65 6d 65 6e 74 20 62 65 |rrent el|ement be|
|00000880| 69 6e 67 0d 0a 61 64 64 | 72 65 73 73 65 64 20 69 |ing..add|ressed i|
|00000890| 6e 20 74 68 65 20 76 69 | 72 74 75 61 6c 20 76 65 |n the vi|rtual ve|
|000008a0| 63 74 6f 72 2e 20 54 68 | 65 20 63 75 72 5c 5f 69 |ctor. Th|e cur\_i|
|000008b0| 6e 64 65 78 20 69 73 20 | 74 68 65 20 69 6e 64 65 |ndex is |the inde|
|000008c0| 78 0d 0a 6f 66 20 74 68 | 65 20 63 75 72 72 65 6e |x..of th|e curren|
|000008d0| 74 20 69 6e 64 65 78 20 | 69 6e 20 74 68 65 20 76 |t index |in the v|
|000008e0| 65 63 74 6f 72 2e 20 4e | 6f 74 65 20 74 68 65 20 |ector. N|ote the |
|000008f0| 69 6e 64 65 78 20 69 73 | 20 61 0d 0a 6c 6f 6e 67 |index is| a..long|
|00000900| 2c 20 73 6f 20 69 6e 64 | 65 78 20 6f 70 65 72 61 |, so ind|ex opera|
|00000910| 74 69 6f 6e 73 20 6d 75 | 73 74 20 62 65 20 63 61 |tions mu|st be ca|
|00000920| 73 74 20 6f 6e 20 6c 6f | 6e 67 20 69 6e 74 65 67 |st on lo|ng integ|
|00000930| 65 72 73 2e 20 20 0d 0a | 54 68 65 73 65 20 74 77 |ers. ..|These tw|
|00000940| 6f 20 76 61 72 69 61 62 | 6c 65 73 20 68 65 6c 70 |o variab|les help|
|00000950| 20 63 6f 6e 74 72 6f 6c | 20 77 68 69 63 68 20 62 | control| which b|
|00000960| 75 66 66 65 72 20 69 73 | 20 73 74 6f 72 65 64 20 |uffer is| stored |
|00000970| 69 6e 0d 0a 74 68 65 20 | 76 6d 65 6d 20 6f 66 20 |in..the |vmem of |
|00000980| 74 68 65 20 68 64 72 2e | 20 54 68 65 20 6d 65 6d |the hdr.| The mem|
|00000990| 62 65 72 20 66 75 6e 63 | 74 69 6f 6e 20 76 61 6c |ber func|tion val|
|000009a0| 28 29 20 72 65 74 75 72 | 6e 73 20 74 68 65 0d 0a |() retur|ns the..|
|000009b0| 63 75 72 72 65 6e 74 20 | 76 61 6c 75 65 2e 0d 0a |current |value...|
|000009c0| 0d 0a 54 68 65 20 73 74 | 61 74 69 63 20 69 6e 74 |..The st|atic int|
|000009d0| 65 67 65 72 2c 20 6e 6f | 62 6a 2c 20 63 6f 75 6e |eger, no|bj, coun|
|000009e0| 74 73 20 74 68 65 20 6e | 75 6d 62 65 72 20 6f 66 |ts the n|umber of|
|000009f0| 20 61 63 74 69 76 65 0d | 0a 76 65 63 74 6f 72 73 | active.|.vectors|
|00000a00| 2e 20 49 66 20 69 74 20 | 69 73 20 7a 65 72 6f 2c |. If it |is zero,|
|00000a10| 20 74 68 65 6e 20 74 68 | 65 20 76 6d 6d 20 73 79 | then th|e vmm sy|
|00000a20| 73 74 65 6d 20 69 73 20 | 69 6e 69 74 69 61 6c 69 |stem is |initiali|
|00000a30| 7a 65 64 0d 0a 69 6e 20 | 74 68 65 20 63 6f 6e 73 |zed..in |the cons|
|00000a40| 74 72 75 63 74 6f 72 73 | 2e 20 54 68 65 20 63 6f |tructors|. The co|
|00000a50| 6e 73 74 72 75 63 74 6f | 72 73 20 69 6e 63 72 65 |nstructo|rs incre|
|00000a60| 6d 65 6e 74 20 6e 6f 62 | 6a 20 61 6e 64 0d 0a 74 |ment nob|j and..t|
|00000a70| 68 65 20 64 65 73 74 72 | 75 63 74 6f 72 73 20 64 |he destr|uctors d|
|00000a80| 65 63 72 65 6d 65 6e 74 | 20 6e 6f 62 6a 2e 0d 0a |ecrement| nobj...|
|00000a90| 0d 0a 54 68 65 20 69 6e | 2d 72 61 6d 20 76 65 72 |..The in|-ram ver|
|00000aa0| 73 69 6f 6e 5c 69 6e 64 | 65 78 7b 76 64 6f 75 62 |sion\ind|ex{vdoub|
|00000ab0| 21 49 4e 2d 52 41 4d 20 | 76 64 6f 75 62 7d 20 61 |!IN-RAM |vdoub} a|
|00000ac0| 6c 73 6f 20 73 65 74 73 | 20 75 70 20 61 0d 0a 76 |lso sets| up a..v|
|00000ad0| 69 72 74 75 61 6c 20 76 | 65 63 74 6f 72 20 73 74 |irtual v|ector st|
|00000ae0| 72 75 63 74 75 72 65 2c | 20 62 75 74 20 69 74 73 |ructure,| but its|
|00000af0| 20 6d 65 6d 6f 72 79 20 | 69 73 20 61 6c 6c 6f 63 | memory |is alloc|
|00000b00| 61 74 65 64 20 65 6e 74 | 69 72 65 6c 79 0d 0a 6f |ated ent|irely..o|
|00000b10| 6e 20 74 68 65 20 68 65 | 61 70 2e 20 54 68 65 20 |n the he|ap. The |
|00000b20| 73 74 72 75 63 74 75 72 | 65 20 69 73 0d 0a 5c 62 |structur|e is..\b|
|00000b30| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0d 0a |egin{ver|batim}..|
|00000b40| 74 79 70 65 64 65 66 20 | 73 74 72 75 63 74 20 76 |typedef |struct v|
|00000b50| 64 6f 75 62 7b 0d 0a 20 | 20 20 20 69 6e 74 20 6e |doub{.. | int n|
|00000b60| 72 65 66 73 3b 0d 0a 20 | 20 20 20 64 6f 75 62 6c |refs;.. | doubl|
|00000b70| 65 20 48 55 47 45 5f 50 | 4f 49 4e 54 45 52 20 2a |e HUGE_P|OINTER *|
|00000b80| 6d 6d 3b 0d 0a 7d 20 76 | 64 6f 75 62 3b 0d 0a 5c |mm;..} v|doub;..\|
|00000b90| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0d 0a 54 |end{verb|atim}..T|
|00000ba0| 68 65 20 76 61 72 69 61 | 62 6c 65 2c 20 6e 72 65 |he varia|ble, nre|
|00000bb0| 66 73 2c 20 73 74 6f 72 | 65 73 20 74 68 65 20 6e |fs, stor|es the n|
|00000bc0| 75 6d 62 65 72 20 6f 66 | 20 72 65 66 65 72 65 6e |umber of| referen|
|00000bd0| 63 65 73 20 74 6f 20 74 | 68 69 73 0d 0a 76 65 63 |ces to t|his..vec|
|00000be0| 74 6f 72 2e 20 54 68 65 | 20 76 65 63 74 6f 72 20 |tor. The| vector |
|00000bf0| 70 6f 69 6e 74 65 72 20 | 2a 6d 6d 20 69 73 20 6e |pointer |*mm is n|
|00000c00| 6f 74 20 66 72 65 65 64 | 20 75 6e 74 69 6c 20 6e |ot freed| until n|
|00000c10| 72 65 66 73 20 69 73 20 | 7a 65 72 6f 2e 0d 0a 4e |refs is |zero...N|
|00000c20| 6f 74 65 20 74 68 69 73 | 20 69 73 20 61 20 74 79 |ote this| is a ty|
|00000c30| 70 65 64 65 66 20 69 6e | 73 74 65 61 64 20 6f 66 |pedef in|stead of|
|00000c40| 20 63 6c 61 73 73 2c 20 | 73 6f 20 74 68 65 20 69 | class, |so the i|
|00000c50| 6e 2d 72 61 6d 20 76 69 | 72 74 75 61 6c 0d 0a 6d |n-ram vi|rtual..m|
|00000c60| 61 74 72 69 78 20 69 73 | 20 6e 6f 74 20 64 65 72 |atrix is| not der|
|00000c70| 69 76 65 64 20 66 72 6f | 6d 20 76 64 6f 75 62 2e |ived fro|m vdoub.|
|00000c80| 20 41 6c 73 6f 20 6e 6f | 74 65 20 74 68 61 74 20 | Also no|te that |
|00000c90| 6d 6d 20 69 73 20 6e 6f | 77 20 61 0d 0a 76 65 63 |mm is no|w a..vec|
|00000ca0| 74 6f 72 20 6f 66 20 68 | 75 67 65 20 64 6f 75 62 |tor of h|uge doub|
|00000cb0| 6c 65 20 70 6f 69 6e 74 | 65 72 73 2e 20 57 68 65 |le point|ers. Whe|
|00000cc0| 6e 20 75 73 69 6e 67 20 | 4d 69 63 72 6f 73 6f 66 |n using |Microsof|
|00000cd0| 74 20 43 2f 43 2b 2b 20 | 37 2e 30 2c 0d 0a 48 55 |t C/C++ |7.0,..HU|
|00000ce0| 47 45 5c 5f 50 4f 49 4e | 54 45 52 20 69 73 20 72 |GE\_POIN|TER is r|
|00000cf0| 65 70 6c 61 63 65 64 20 | 62 79 20 5c 5f 5c 5f 68 |eplaced |by \_\_h|
|00000d00| 75 67 65 2c 20 61 6e 64 | 20 69 74 20 69 73 20 72 |uge, and| it is r|
|00000d10| 65 70 6c 61 63 65 64 20 | 62 79 20 66 61 72 20 69 |eplaced |by far i|
|00000d20| 6e 0d 0a 42 6f 72 6c 61 | 6e 64 20 43 2b 2b 2e 20 |n..Borla|nd C++. |
|00000d30| 49 66 20 79 6f 75 20 70 | 6f 72 74 20 74 68 65 20 |If you p|ort the |
|00000d40| 49 4e 5c 5f 52 41 4d 20 | 76 65 72 73 69 6f 6e 20 |IN\_RAM |version |
|00000d50| 74 6f 20 6f 74 68 65 72 | 20 63 6f 6d 70 69 6c 65 |to other| compile|
|00000d60| 72 73 2c 0d 0a 48 55 47 | 45 5c 5f 50 4f 49 4e 54 |rs,..HUG|E\_POINT|
|00000d70| 45 52 5c 69 6e 64 65 78 | 7b 76 64 6f 75 62 21 48 |ER\index|{vdoub!H|
|00000d80| 55 47 45 5c 5f 50 4f 49 | 4e 54 45 52 7d 20 69 73 |UGE\_POI|NTER} is|
|00000d90| 20 64 65 66 69 6e 65 64 | 20 61 73 20 62 6c 61 6e | defined| as blan|
|00000da0| 6b 2e 20 59 6f 75 0d 0a | 63 61 6e 20 72 65 64 65 |k. You..|can rede|
|00000db0| 66 69 6e 65 20 69 74 20 | 69 66 20 79 6f 75 20 63 |fine it |if you c|
|00000dc0| 6f 6d 70 69 6c 65 72 20 | 68 61 73 20 70 72 6f 62 |ompiler |has prob|
|00000dd0| 6c 65 6d 73 20 72 65 6c | 65 61 73 69 6e 67 20 6c |lems rel|easing l|
|00000de0| 61 72 67 65 0d 0a 62 6c | 6f 63 6b 73 20 6f 66 20 |arge..bl|ocks of |
|00000df0| 6d 65 6d 6f 72 79 20 77 | 68 65 6e 20 74 68 65 20 |memory w|hen the |
|00000e00| 70 6f 69 6e 74 65 72 20 | 74 79 70 65 20 6f 66 20 |pointer |type of |
|00000e10| 6d 6d 20 69 73 20 75 6e | 64 65 63 6c 61 72 65 64 |mm is un|declared|
|00000e20| 2e 0d 0a 28 54 68 69 73 | 20 6f 63 63 75 72 65 64 |...(This| occured|
|00000e30| 20 69 6e 20 61 6e 20 65 | 61 72 6c 79 20 72 65 6c | in an e|arly rel|
|00000e40| 65 61 73 65 20 6f 66 20 | 4d 53 43 37 2e 30 29 2e |ease of |MSC7.0).|
|00000e50| 0d 0a 0d 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |....\sub|section{|
|00000e60| 50 75 62 6c 69 63 20 50 | 61 72 74 73 20 6f 66 20 |Public P|arts of |
|00000e70| 61 20 76 64 6f 75 62 7d | 0d 0a 54 68 65 20 70 75 |a vdoub}|..The pu|
|00000e80| 62 6c 69 63 20 66 75 6e | 63 74 69 6f 6e 73 20 67 |blic fun|ctions g|
|00000e90| 69 76 65 20 61 63 63 65 | 73 73 20 74 6f 20 74 68 |ive acce|ss to th|
|00000ea0| 65 20 76 6d 6d 2e 20 54 | 68 65 20 66 75 6e 63 74 |e vmm. T|he funct|
|00000eb0| 69 6f 6e 0d 0a 47 61 72 | 62 61 67 65 28 29 5c 69 |ion..Gar|bage()\i|
|00000ec0| 6e 64 65 78 7b 76 64 6f | 75 62 21 47 61 72 62 61 |ndex{vdo|ub!Garba|
|00000ed0| 67 65 28 29 7d 20 73 69 | 6d 70 6c 79 20 63 68 65 |ge()} si|mply che|
|00000ee0| 63 6b 73 20 69 66 20 74 | 68 65 20 73 69 67 6e 61 |cks if t|he signa|
|00000ef0| 74 75 72 65 20 69 73 0d | 0a 63 6f 72 72 65 63 74 |ture is.|.correct|
|00000f00| 2e 20 54 68 69 73 20 69 | 6e 64 69 63 61 74 65 73 |. This i|ndicates|
|00000f10| 20 74 68 61 74 20 74 68 | 65 20 76 64 6f 75 62 20 | that th|e vdoub |
|00000f20| 69 73 20 6c 69 6b 65 6c | 79 20 69 6e 74 61 63 74 |is likel|y intact|
|00000f30| 20 61 6e 64 0d 0a 61 63 | 74 69 76 65 2e 20 0d 0a | and..ac|tive. ..|
|00000f40| 0d 0a 54 68 65 20 63 6f | 6e 73 74 72 75 63 74 6f |..The co|nstructo|
|00000f50| 72 73 5c 69 6e 64 65 78 | 7b 76 64 6f 75 62 21 63 |rs\index|{vdoub!c|
|00000f60| 6f 6e 73 74 72 75 63 74 | 6f 72 73 7d 20 61 63 63 |onstruct|ors} acc|
|00000f70| 65 70 74 20 76 6f 69 64 | 2c 0d 0a 6c 6f 6e 67 20 |ept void|,..long |
|00000f80| 6f 72 20 76 64 6f 75 62 | 5c 26 20 20 61 72 67 75 |or vdoub|\& argu|
|00000f90| 6d 65 6e 74 73 2e 20 20 | 54 68 65 20 64 65 66 61 |ments. |The defa|
|00000fa0| 75 6c 74 20 63 6f 6e 73 | 74 72 75 63 74 6f 72 0d |ult cons|tructor.|
|00000fb0| 0a 61 63 63 65 70 74 73 | 20 61 20 76 6f 69 64 2e |.accepts| a void.|
|00000fc0| 20 49 74 20 61 6c 6c 6f | 63 61 74 65 73 20 61 20 | It allo|cates a |
|00000fd0| 68 64 72 20 6f 6e 20 74 | 68 65 20 76 6d 6d 20 77 |hdr on t|he vmm w|
|00000fe0| 69 74 68 20 6f 6e 65 0d | 0a 64 6f 75 62 6c 65 2e |ith one.|.double.|
|00000ff0| 20 54 68 65 20 73 65 63 | 6f 6e 64 20 63 6f 6e 73 | The sec|ond cons|
|00001000| 74 72 75 63 74 6f 72 20 | 64 6f 65 73 20 74 68 65 |tructor |does the|
|00001010| 20 73 61 6d 65 2c 20 62 | 75 74 20 74 68 65 20 68 | same, b|ut the h|
|00001020| 64 72 0d 0a 63 6f 6e 74 | 61 69 6e 73 20 61 72 72 |dr..cont|ains arr|
|00001030| 61 79 5c 5f 73 69 7a 65 | 20 65 6c 65 6d 65 6e 74 |ay\_size| element|
|00001040| 73 2e 20 54 68 65 20 63 | 6f 6e 73 74 72 75 63 74 |s. The c|onstruct|
|00001050| 6f 72 20 77 69 74 68 20 | 61 20 76 64 6f 75 62 0d |or with |a vdoub.|
|00001060| 0a 72 65 66 65 72 65 6e | 63 65 20 61 72 67 75 6d |.referen|ce argum|
|00001070| 65 6e 74 20 63 6f 70 69 | 65 73 20 6f 6e 65 20 76 |ent copi|es one v|
|00001080| 64 6f 75 62 20 69 6e 74 | 6f 20 61 6e 6f 74 68 65 |doub int|o anothe|
|00001090| 72 2e 20 45 61 63 68 0d | 0a 63 6f 6e 73 74 72 75 |r. Each.|.constru|
|000010a0| 63 74 6f 72 20 69 6e 63 | 72 65 6d 65 6e 74 73 20 |ctor inc|rements |
|000010b0| 6e 6f 62 6a 2c 20 61 6e | 64 20 63 61 6c 6c 73 0d |nobj, an|d calls.|
|000010c0| 0a 76 6f 70 65 6e 28 29 | 5c 69 6e 64 65 78 7b 76 |.vopen()|\index{v|
|000010d0| 6d 6d 21 76 6f 70 65 6e | 28 29 7d 20 69 66 20 6e |mm!vopen|()} if n|
|000010e0| 6f 62 6a 20 69 73 20 7a | 65 72 6f 2e 0d 0a 0d 0a |obj is z|ero.....|
|000010f0| 54 68 65 20 64 65 73 74 | 72 75 63 74 6f 72 5c 69 |The dest|ructor\i|
|00001100| 6e 64 65 78 7b 76 64 6f | 75 62 21 64 65 73 74 72 |ndex{vdo|ub!destr|
|00001110| 75 63 74 6f 72 7d 20 66 | 72 65 65 73 20 74 68 65 |uctor} f|rees the|
|00001120| 20 68 65 61 64 65 72 2e | 20 49 66 0d 0a 74 68 65 | header.| If..the|
|00001130| 20 68 64 72 20 69 73 20 | 66 72 65 65 64 20 77 69 | hdr is |freed wi|
|00001140| 74 68 20 65 72 72 6f 72 | 2c 20 74 68 65 20 73 79 |th error|, the sy|
|00001150| 73 74 65 6d 20 73 74 6f | 70 73 2e 20 4f 74 68 65 |stem sto|ps. Othe|
|00001160| 72 77 69 73 65 2c 0d 0a | 74 68 65 20 73 69 67 6e |rwise,..|the sign|
|00001170| 61 74 75 72 65 20 69 73 | 20 73 65 74 20 74 6f 20 |ature is| set to |
|00001180| 7a 65 72 6f 20 61 6e 64 | 20 6e 6f 62 6a 20 69 73 |zero and| nobj is|
|00001190| 20 64 65 63 72 65 6d 65 | 6e 74 65 64 2e 20 49 66 | decreme|nted. If|
|000011a0| 0d 0a 6e 6f 62 6a 20 69 | 73 20 64 65 63 72 65 6d |..nobj i|s decrem|
|000011b0| 65 6e 74 65 64 20 74 6f | 20 7a 65 72 6f 2c 20 74 |ented to| zero, t|
|000011c0| 68 65 6e 20 76 63 6c 6f | 73 65 28 29 5c 69 6e 64 |hen vclo|se()\ind|
|000011d0| 65 78 7b 76 6d 6d 21 76 | 63 6c 6f 73 65 28 29 7d |ex{vmm!v|close()}|
|000011e0| 0d 0a 69 73 20 63 61 6c | 6c 65 64 2e 20 4e 6f 74 |..is cal|led. Not|
|000011f0| 65 20 74 68 61 74 20 74 | 68 69 73 20 64 6f 65 73 |e that t|his does|
|00001200| 20 6e 6f 74 20 67 75 61 | 72 61 6e 74 65 65 20 74 | not gua|rantee t|
|00001210| 68 61 74 20 76 63 6c 6f | 73 65 28 29 0d 0a 77 69 |hat vclo|se()..wi|
|00001220| 6c 6c 20 62 65 20 63 61 | 6c 6c 65 64 20 77 68 65 |ll be ca|lled whe|
|00001230| 6e 20 74 68 65 20 70 72 | 6f 67 72 61 6d 20 6c 65 |n the pr|ogram le|
|00001240| 61 76 65 73 20 74 68 65 | 20 6d 61 69 6e 28 29 20 |aves the| main() |
|00001250| 66 75 6e 63 74 69 6f 6e | 0d 0a 62 65 63 61 75 73 |function|..becaus|
|00001260| 65 20 73 6f 6d 65 20 76 | 69 72 74 75 61 6c 20 6d |e some v|irtual m|
|00001270| 61 74 72 69 63 65 73 20 | 61 72 65 20 63 6f 6e 73 |atrices |are cons|
|00001280| 74 72 75 63 74 65 64 20 | 6f 75 74 73 69 64 65 20 |tructed |outside |
|00001290| 6f 66 0d 0a 74 68 65 20 | 73 63 6f 70 65 20 6f 66 |of..the |scope of|
|000012a0| 20 6d 61 69 6e 28 29 2e | 20 54 68 65 20 6d 61 74 | main().| The mat|
|000012b0| 72 69 78 20 73 74 61 63 | 6b 20 64 69 73 70 61 74 |rix stac|k dispat|
|000012c0| 63 68 65 72 20 69 73 20 | 61 0d 0a 70 6f 69 6e 74 |cher is |a..point|
|000012d0| 65 72 20 74 6f 20 74 68 | 65 20 62 61 73 65 20 6f |er to th|e base o|
|000012e0| 66 20 61 20 73 74 61 63 | 6b 20 6f 66 20 6d 61 74 |f a stac|k of mat|
|000012f0| 72 69 63 65 73 2e 20 49 | 74 20 69 73 20 61 6c 6c |rices. I|t is all|
|00001300| 6f 63 61 74 65 64 0d 0a | 6f 75 74 73 69 64 65 20 |ocated..|outside |
|00001310| 6f 66 20 74 68 65 20 66 | 75 6e 63 74 69 6f 6e 20 |of the f|unction |
|00001320| 6d 61 69 6e 28 29 20 73 | 6f 20 69 74 20 77 69 6c |main() s|o it wil|
|00001330| 6c 20 6e 6f 74 20 62 65 | 20 64 65 73 74 72 6f 79 |l not be| destroy|
|00001340| 65 64 0d 0a 75 70 6f 6e | 20 6c 65 61 76 69 6e 67 |ed..upon| leaving|
|00001350| 20 6d 61 69 6e 28 29 2e | 20 20 54 68 75 73 2c 20 | main().| Thus, |
|00001360| 76 63 6c 6f 73 65 28 29 | 20 6d 75 73 74 20 62 65 |vclose()| must be|
|00001370| 20 63 61 6c 6c 65 64 20 | 62 65 66 6f 72 65 0d 0a | called |before..|
|00001380| 6c 65 61 76 69 6e 67 20 | 6d 61 69 6e 28 29 2e 20 |leaving |main(). |
|00001390| 54 68 65 20 6e 65 78 74 | 20 74 69 6d 65 20 74 68 |The next| time th|
|000013a0| 65 20 64 65 73 74 72 75 | 63 74 6f 72 20 69 73 20 |e destru|ctor is |
|000013b0| 63 61 6c 6c 65 64 2c 0d | 0a 76 66 72 65 65 28 29 |called,.|.vfree()|
|000013c0| 20 77 69 6c 6c 20 72 65 | 74 75 72 6e 20 61 6e 20 | will re|turn an |
|000013d0| 65 72 72 6f 72 20 73 6f | 20 74 68 65 20 70 72 6f |error so| the pro|
|000013e0| 67 72 61 6d 20 77 69 6c | 6c 20 65 78 69 74 0d 0a |gram wil|l exit..|
|000013f0| 74 68 72 6f 75 67 68 20 | 74 68 65 20 6c 61 73 74 |through |the last|
|00001400| 20 64 65 73 74 72 75 63 | 74 6f 72 20 63 61 6c 6c | destruc|tor call|
|00001410| 2e 0d 0a 0d 0a 54 68 65 | 20 66 75 6e 63 74 69 6f |.....The| functio|
|00001420| 6e 20 76 28 29 5c 69 6e | 64 65 78 7b 76 64 6f 75 |n v()\in|dex{vdou|
|00001430| 62 21 76 28 29 7d 20 67 | 65 74 73 20 74 68 65 20 |b!v()} g|ets the |
|00001440| 76 61 6c 75 65 20 61 74 | 20 69 6e 64 65 78 2e 0d |value at| index..|
|00001450| 0a 49 74 20 63 61 6c 6c | 73 20 76 72 65 61 64 28 |.It call|s vread(|
|00001460| 29 20 61 6e 64 20 72 65 | 74 75 72 6e 73 20 74 68 |) and re|turns th|
|00001470| 65 20 76 61 6c 75 65 2e | 20 49 74 20 61 6c 73 6f |e value.| It also|
|00001480| 20 73 65 74 73 0d 0a 63 | 75 72 5c 5f 69 6e 64 65 | sets..c|ur\_inde|
|00001490| 78 20 74 6f 20 69 6e 64 | 65 78 2c 20 61 6e 64 20 |x to ind|ex, and |
|000014a0| 73 74 6f 72 65 73 20 74 | 68 65 20 63 75 72 72 65 |stores t|he curre|
|000014b0| 6e 74 20 76 61 6c 75 65 | 20 69 6e 0d 0a 2a 63 75 |nt value| in..*cu|
|000014c0| 72 5c 5f 65 6c 65 2e 20 | 4e 6f 74 65 20 74 68 61 |r\_ele. |Note tha|
|000014d0| 74 20 74 68 65 20 63 61 | 6c 6c 20 74 6f 20 76 72 |t the ca|ll to vr|
|000014e0| 65 61 64 28 29 20 6d 61 | 79 20 63 68 61 6e 67 65 |ead() ma|y change|
|000014f0| 20 74 68 65 0d 0a 70 61 | 67 65 20 74 68 65 20 62 | the..pa|ge the b|
|00001500| 75 66 66 65 72 20 69 6e | 20 76 6d 65 6d 2e 0d 0a |uffer in| vmem...|
|00001510| 0d 0a 54 68 65 20 62 72 | 61 63 6b 65 74 73 20 6f |..The br|ackets o|
|00001520| 70 65 72 61 74 6f 72 5c | 69 6e 64 65 78 7b 76 64 |perator\|index{vd|
|00001530| 6f 75 62 21 5b 5d 20 6f | 70 65 72 61 74 6f 72 7d |oub![] o|perator}|
|00001540| 20 70 72 6f 76 69 64 65 | 73 0d 0a 74 68 65 20 73 | provide|s..the s|
|00001550| 61 6d 65 20 66 75 6e 63 | 74 69 6f 6e 20 61 73 20 |ame func|tion as |
|00001560| 76 28 29 2c 20 62 75 74 | 20 79 6f 75 20 63 61 6e |v(), but| you can|
|00001570| 20 75 73 65 20 74 68 65 | 20 76 65 63 74 6f 72 0d | use the| vector.|
|00001580| 0a 6e 6f 74 61 74 69 6f | 6e 20 74 6f 20 64 6f 20 |.notatio|n to do |
|00001590| 69 74 2e 20 48 6f 77 65 | 76 65 72 20 69 74 20 69 |it. Howe|ver it i|
|000015a0| 73 20 62 61 73 69 63 61 | 6c 6c 79 20 76 65 72 79 |s basica|lly very|
|000015b0| 20 64 69 66 66 65 72 65 | 6e 74 0d 0a 74 68 61 6e | differe|nt..than|
|000015c0| 20 61 63 63 65 73 73 69 | 6e 67 20 61 6e 20 65 6c | accessi|ng an el|
|000015d0| 65 6d 65 6e 74 20 6f 6e | 20 74 68 65 20 68 65 61 |ement on| the hea|
|000015e0| 70 2c 20 6f 72 20 73 6f | 6d 65 20 6f 66 66 73 65 |p, or so|me offse|
|000015f0| 74 20 66 72 6f 6d 0d 0a | 61 20 70 6f 69 6e 74 65 |t from..|a pointe|
|00001600| 72 20 62 61 73 65 2e 20 | 54 68 65 20 63 61 6c 6c |r base. |The call|
|00001610| 20 74 6f 20 76 72 65 61 | 64 28 29 20 73 68 69 66 | to vrea|d() shif|
|00001620| 74 73 20 61 20 6e 65 77 | 20 70 61 67 65 20 69 6e |ts a new| page in|
|00001630| 74 6f 0d 0a 52 41 4d 20 | 69 66 20 6e 65 63 65 73 |to..RAM |if neces|
|00001640| 73 61 72 79 2e 20 54 68 | 65 20 6e 6f 72 6d 61 6c |sary. Th|e normal|
|00001650| 20 75 73 65 20 6f 66 20 | 74 68 65 20 62 72 61 63 | use of |the brac|
|00001660| 6b 65 74 73 20 6f 70 65 | 72 61 74 6f 72 0d 0a 6a |kets ope|rator..j|
|00001670| 75 73 74 20 61 63 63 65 | 73 73 65 73 20 52 41 4d |ust acce|sses RAM|
|00001680| 2e 20 54 68 69 73 20 68 | 61 73 20 73 69 64 65 20 |. This h|as side |
|00001690| 65 66 66 65 63 74 73 20 | 69 6e 20 74 68 65 20 61 |effects |in the a|
|000016a0| 73 73 69 67 6e 6d 65 6e | 74 0d 0a 6f 70 65 72 61 |ssignmen|t..opera|
|000016b0| 74 69 6f 6e 20 6f 6e 20 | 76 69 72 74 75 61 6c 20 |tion on |virtual |
|000016c0| 76 65 63 74 6f 72 73 2e | 0d 0a 0d 0a 54 68 65 20 |vectors.|....The |
|000016d0| 64 69 66 66 65 72 65 6e | 63 65 20 62 65 74 77 65 |differen|ce betwe|
|000016e0| 65 6e 20 76 28 29 20 61 | 6e 64 20 74 68 65 20 62 |en v() a|nd the b|
|000016f0| 72 61 63 6b 65 74 73 20 | 6f 70 65 72 61 74 6f 72 |rackets |operator|
|00001700| 20 69 73 0d 0a 74 68 65 | 79 20 68 61 76 65 20 64 | is..the|y have d|
|00001710| 69 66 66 65 72 65 6e 74 | 20 72 65 74 75 72 6e 20 |ifferent| return |
|00001720| 74 79 70 65 73 2e 20 76 | 28 29 20 72 65 74 75 72 |types. v|() retur|
|00001730| 6e 73 20 61 20 64 6f 75 | 62 6c 65 20 61 6e 64 0d |ns a dou|ble and.|
|00001740| 0a 76 64 6f 75 62 3a 3a | 6f 70 65 72 61 74 6f 72 |.vdoub::|operator|
|00001750| 5b 5d 20 72 65 74 75 72 | 6e 73 20 61 20 72 65 66 |[] retur|ns a ref|
|00001760| 65 72 65 6e 63 65 20 74 | 6f 20 61 6e 6f 74 68 65 |erence t|o anothe|
|00001770| 72 20 76 64 6f 75 62 2e | 20 54 6f 0d 0a 71 75 6f |r vdoub.| To..quo|
|00001780| 74 65 20 48 6f 6c 75 62 | 3a 20 0d 0a 5c 62 65 67 |te Holub|: ..\beg|
|00001790| 69 6e 7b 71 75 6f 74 65 | 7d 0d 0a 54 68 65 20 62 |in{quote|}..The b|
|000017a0| 72 61 63 6b 65 74 73 20 | 6f 70 65 72 61 74 6f 72 |rackets |operator|
|000017b0| 20 69 73 20 61 20 7b 5c | 65 6d 20 73 65 6c 65 63 | is a {\|em selec|
|000017c0| 74 6f 72 20 7d 20 6f 70 | 65 72 61 74 6f 72 2e 20 |tor } op|erator. |
|000017d0| 49 74 0d 0a 73 65 74 73 | 20 74 68 69 6e 67 73 20 |It..sets| things |
|000017e0| 75 70 20 73 6f 20 74 68 | 61 74 20 74 68 65 20 6e |up so th|at the n|
|000017f0| 65 78 74 20 6f 70 65 72 | 61 74 69 6f 6e 20 63 61 |ext oper|ation ca|
|00001800| 6e 20 61 63 63 65 73 73 | 20 74 68 65 0d 0a 61 72 |n access| the..ar|
|00001810| 72 61 79 20 65 6c 65 6d | 65 6e 74 20 73 65 6c 65 |ray elem|ent sele|
|00001820| 63 74 65 64 20 62 79 20 | 74 68 65 20 70 72 65 76 |cted by |the prev|
|00001830| 69 6f 75 73 20 62 72 61 | 63 6b 65 74 2e 20 49 66 |ious bra|cket. If|
|00001840| 20 74 68 65 20 7b 5c 65 | 6d 0d 0a 6e 65 78 74 7d | the {\e|m..next}|
|00001850| 20 6f 70 65 72 61 74 69 | 6f 6e 20 6d 6f 64 69 66 | operati|on modif|
|00001860| 69 65 73 20 74 68 65 20 | 61 72 72 61 79 20 65 6c |ies the |array el|
|00001870| 65 6d 65 6e 74 2c 20 74 | 68 65 6e 20 74 68 61 74 |ement, t|hen that|
|00001880| 0d 0a 6f 70 65 72 61 74 | 69 6f 6e 20 73 65 74 73 |..operat|ion sets|
|00001890| 20 74 68 65 20 64 69 72 | 74 79 20 62 69 74 2e 0d | the dir|ty bit..|
|000018a0| 0a 5c 65 6e 64 7b 71 75 | 6f 74 65 7d 20 20 0d 0a |.\end{qu|ote} ..|
|000018b0| 0d 0a 5c 73 65 63 74 69 | 6f 6e 7b 41 73 73 69 67 |..\secti|on{Assig|
|000018c0| 6e 6d 65 6e 74 20 69 6e | 20 76 64 6f 75 62 7d 20 |nment in| vdoub} |
|000018d0| 0d 0a 0d 0a 41 73 73 69 | 67 6e 6d 65 6e 74 5c 69 |....Assi|gnment\i|
|000018e0| 6e 64 65 78 7b 76 64 6f | 75 62 21 3d 7d 20 74 61 |ndex{vdo|ub!=} ta|
|000018f0| 6b 65 73 20 74 77 6f 20 | 66 6f 72 6d 73 20 66 6f |kes two |forms fo|
|00001900| 72 20 76 69 72 74 75 61 | 6c 20 76 65 63 74 6f 72 |r virtua|l vector|
|00001910| 73 2e 20 54 68 65 20 70 | 72 6f 62 6c 65 6d 0d 0a |s. The p|roblem..|
|00001920| 69 73 20 74 6f 20 6d 61 | 6b 65 20 74 68 65 20 63 |is to ma|ke the c|
|00001930| 6f 64 65 20 77 6f 72 6b | 20 66 6f 72 20 73 61 79 |ode work| for say|
|00001940| 69 6e 67 20 5c 76 65 72 | 62 2b 20 76 65 63 74 5b |ing \ver|b+ vect[|
|00001950| 69 5d 20 3d 20 35 2b 20 | 6f 72 0d 0a 66 6f 72 20 |i] = 5+ |or..for |
|00001960| 73 61 79 69 6e 67 20 5c | 76 65 72 62 2b 20 76 65 |saying \|verb+ ve|
|00001970| 63 74 31 20 3d 20 76 65 | 63 74 32 2b 2e 20 54 68 |ct1 = ve|ct2+. Th|
|00001980| 65 20 66 69 72 73 74 20 | 66 6f 72 6d 20 6f 66 0d |e first |form of.|
|00001990| 0a 61 73 73 69 67 6e 6d | 65 6e 74 20 69 73 20 0d |.assignm|ent is .|
|000019a0| 0a 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |.\begin{|verbatim|
|000019b0| 7d 0d 0a 64 6f 75 62 6c | 65 20 76 64 6f 75 62 3a |}..doubl|e vdoub:|
|000019c0| 3a 6f 70 65 72 61 74 6f | 72 20 3d 20 28 20 64 6f |:operato|r = ( do|
|000019d0| 75 62 6c 65 20 64 20 29 | 0d 0a 20 20 7b 0d 0a 20 |uble d )|.. {.. |
|000019e0| 20 20 20 69 66 20 28 20 | 47 61 72 62 61 67 65 28 | if ( |Garbage(|
|000019f0| 29 20 29 20 7b 0d 0a 20 | 20 20 20 20 20 70 65 72 |) ) {.. | per|
|00001a00| 72 6f 72 28 22 56 4d 53 | 20 61 73 73 69 67 6e 6d |ror("VMS| assignm|
|00001a10| 65 6e 74 20 65 72 72 6f | 72 2c 20 73 6f 75 72 63 |ent erro|r, sourc|
|00001a20| 65 20 69 73 20 47 61 72 | 62 61 67 65 28 3d 29 22 |e is Gar|bage(=)"|
|00001a30| 29 3b 0d 0a 20 20 20 20 | 20 20 65 78 69 74 28 31 |);.. | exit(1|
|00001a40| 29 3b 0d 0a 20 20 20 20 | 7d 0d 0a 20 20 20 20 2a |);.. |}.. *|
|00001a50| 63 75 72 5f 65 6c 65 20 | 3d 20 64 3b 0d 0a 20 20 |cur_ele |= d;.. |
|00001a60| 20 20 76 64 69 72 74 79 | 28 20 68 64 72 20 29 3b | vdirty|( hdr );|
|00001a70| 0d 0a 20 20 20 20 72 65 | 74 75 72 6e 20 64 3b 0d |.. re|turn d;.|
|00001a80| 0a 20 20 7d 0d 0a 5c 65 | 6e 64 7b 76 65 72 62 61 |. }..\e|nd{verba|
|00001a90| 74 69 6d 7d 0d 0a 0d 0a | 54 68 65 20 66 75 6e 63 |tim}....|The func|
|00001aa0| 74 69 6f 6e 61 6c 20 66 | 6f 72 6d 20 6f 66 20 5c |tional f|orm of \|
|00001ab0| 76 65 72 62 2b 20 76 65 | 63 74 5b 69 5d 20 3d 20 |verb+ ve|ct[i] = |
|00001ac0| 35 2b 20 69 73 20 0d 0a | 5c 76 65 72 62 2b 20 28 |5+ is ..|\verb+ (|
|00001ad0| 76 65 63 74 2e 6f 70 65 | 72 61 74 6f 72 5b 5d 28 |vect.ope|rator[](|
|00001ae0| 69 29 29 2e 6f 70 65 72 | 61 74 6f 72 3d 28 35 29 |i)).oper|ator=(5)|
|00001af0| 2b 2e 20 46 69 72 73 74 | 20 74 68 65 0d 0a 62 72 |+. First| the..br|
|00001b00| 61 63 6b 65 74 73 20 6f | 70 65 72 61 74 6f 72 20 |ackets o|perator |
|00001b10| 69 73 20 63 61 6c 6c 65 | 64 2c 20 77 68 69 63 68 |is calle|d, which|
|00001b20| 20 73 65 74 73 20 74 68 | 65 20 63 75 72 72 65 6e | sets th|e curren|
|00001b30| 74 20 69 6e 64 65 78 0d | 0a 74 6f 20 69 2e 20 20 |t index.|.to i. |
|00001b40| 53 69 6e 63 65 20 74 68 | 65 20 62 72 61 63 6b 65 |Since th|e bracke|
|00001b50| 74 20 6f 70 65 72 61 74 | 6f 72 20 72 65 74 75 72 |t operat|or retur|
|00001b60| 6e 73 20 61 20 72 65 66 | 65 72 65 6e 63 65 20 74 |ns a ref|erence t|
|00001b70| 6f 20 61 0d 0a 76 64 6f | 75 62 2c 20 74 68 65 20 |o a..vdo|ub, the |
|00001b80| 76 64 6f 75 62 3a 3a 6f | 70 65 72 61 74 6f 72 3d |vdoub::o|perator=|
|00001b90| 28 35 29 20 69 73 20 63 | 61 6c 6c 65 64 2e 20 20 |(5) is c|alled. |
|00001ba0| 54 68 65 20 63 75 72 72 | 65 6e 74 0d 0a 65 6c 65 |The curr|ent..ele|
|00001bb0| 6d 65 6e 74 20 6f 66 20 | 74 68 65 20 72 65 74 75 |ment of |the retu|
|00001bc0| 72 6e 65 64 20 76 64 6f | 75 62 20 69 73 20 73 65 |rned vdo|ub is se|
|00001bd0| 74 20 74 6f 20 35 2e 20 | 4e 65 78 74 20 74 68 65 |t to 5. |Next the|
|00001be0| 20 62 75 66 66 65 72 0d | 0a 69 73 20 64 65 63 6c | buffer.|.is decl|
|00001bf0| 61 72 65 64 20 64 69 72 | 74 79 2c 20 61 6e 64 20 |ared dir|ty, and |
|00001c00| 74 68 65 20 35 20 69 73 | 20 72 65 74 75 72 6e 65 |the 5 is| returne|
|00001c10| 64 2e 0d 0a 0d 0a 54 68 | 65 20 6f 74 68 65 72 20 |d.....Th|e other |
|00001c20| 66 6f 72 6d 20 6f 66 20 | 61 73 73 69 67 6e 6d 65 |form of |assignme|
|00001c30| 6e 74 20 63 6f 70 69 65 | 73 20 61 20 64 6f 75 62 |nt copie|s a doub|
|00001c40| 6c 65 20 76 65 63 74 6f | 72 20 74 6f 0d 0a 61 6e |le vecto|r to..an|
|00001c50| 6f 74 68 65 72 2e 20 49 | 74 20 64 69 73 70 6f 73 |other. I|t dispos|
|00001c60| 65 73 20 74 68 65 20 6c | 65 66 74 20 6f 70 65 72 |es the l|eft oper|
|00001c70| 61 6e 64 20 68 64 72 20 | 69 66 20 69 74 20 61 6c |and hdr |if it al|
|00001c80| 72 65 61 64 79 0d 0a 65 | 78 69 73 74 73 2c 20 74 |ready..e|xists, t|
|00001c90| 68 65 6e 20 61 6c 6c 6f | 63 61 74 65 73 20 61 20 |hen allo|cates a |
|00001ca0| 6e 65 77 20 68 64 72 2e | 20 54 68 65 6e 20 69 74 |new hdr.| Then it|
|00001cb0| 20 63 6f 70 69 65 73 20 | 74 68 65 0d 0a 63 6f 6e | copies |the..con|
|00001cc0| 74 65 6e 74 73 20 66 72 | 6f 6d 20 76 20 74 6f 20 |tents fr|om v to |
|00001cd0| 74 68 65 20 6e 65 77 20 | 68 64 72 2e 20 54 68 65 |the new |hdr. The|
|00001ce0| 20 63 6f 64 65 20 69 73 | 20 67 69 76 65 6e 20 62 | code is| given b|
|00001cf0| 79 0d 0a 0d 0a 5c 62 65 | 67 69 6e 7b 76 65 72 62 |y....\be|gin{verb|
|00001d00| 61 74 69 6d 7d 0d 0a 64 | 6f 75 62 6c 65 20 76 64 |atim}..d|ouble vd|
|00001d10| 6f 75 62 3a 3a 6f 70 65 | 72 61 74 6f 72 20 3d 20 |oub::ope|rator = |
|00001d20| 28 20 76 64 6f 75 62 20 | 26 76 29 0d 0a 2f 2f 20 |( vdoub |&v)..// |
|00001d30| 63 6f 70 79 20 76 65 63 | 74 6f 72 20 76 20 74 6f |copy vec|tor v to|
|00001d40| 20 76 65 63 74 6f 72 20 | 74 0d 0a 20 20 7b 0d 0a | vector |t.. {..|
|00001d50| 20 20 20 20 20 69 66 28 | 20 76 2e 47 61 72 62 61 | if(| v.Garba|
|00001d60| 67 65 28 29 20 29 7b 0d | 0a 20 20 20 20 20 20 20 |ge() ){.|. |
|00001d70| 70 65 72 72 6f 72 28 22 | 56 4d 53 20 63 6f 70 79 |perror("|VMS copy|
|00001d80| 20 65 72 72 6f 72 2c 20 | 73 6f 75 72 63 65 20 69 | error, |source i|
|00001d90| 73 20 47 61 72 62 61 67 | 65 22 29 3b 0d 0a 20 20 |s Garbag|e");.. |
|00001da0| 20 20 20 20 20 65 78 69 | 74 28 31 29 3b 0d 0a 20 | exi|t(1);.. |
|00001db0| 20 20 20 20 7d 0d 0a 20 | 20 20 20 69 66 28 20 21 | }.. | if( !|
|00001dc0| 47 61 72 62 61 67 65 28 | 29 20 29 20 76 66 72 65 |Garbage(|) ) vfre|
|00001dd0| 65 28 20 68 64 72 20 29 | 3b 20 2f 2f 20 72 65 70 |e( hdr )|; // rep|
|00001de0| 6c 61 63 65 20 68 64 72 | 20 69 66 20 74 20 69 73 |lace hdr| if t is|
|00001df0| 20 61 63 74 69 76 65 0d | 0a 0d 0a 20 20 20 20 64 | active.|... d|
|00001e00| 6f 75 62 6c 65 20 2a 70 | 3b 0d 0a 20 20 20 20 6c |ouble *p|;.. l|
|00001e10| 6f 6e 67 20 6e 75 6d 65 | 6c 65 20 3d 20 76 65 6c |ong nume|le = vel|
|00001e20| 65 28 20 76 2e 68 64 72 | 20 29 3b 0d 0a 20 20 20 |e( v.hdr| );.. |
|00001e30| 20 73 69 67 6e 61 74 75 | 72 65 20 3d 20 53 49 47 | signatu|re = SIG|
|00001e40| 4e 41 54 55 52 45 3b 0d | 0a 20 20 20 20 2a 63 75 |NATURE;.|. *cu|
|00001e50| 72 5f 65 6c 65 20 3d 20 | 2a 76 2e 63 75 72 5f 65 |r_ele = |*v.cur_e|
|00001e60| 6c 65 3b 0d 0a 20 20 20 | 20 63 75 72 5f 69 6e 64 |le;.. | cur_ind|
|00001e70| 65 78 20 3d 20 76 2e 63 | 75 72 5f 69 6e 64 65 78 |ex = v.c|ur_index|
|00001e80| 3b 0d 0a 20 20 20 20 0d | 0a 20 20 20 20 69 66 20 |;.. .|. if |
|00001e90| 28 20 21 28 68 64 72 20 | 3d 20 76 6d 61 6c 6c 6f |( !(hdr |= vmallo|
|00001ea0| 63 28 20 6e 75 6d 65 6c | 65 2c 20 73 69 7a 65 6f |c( numel|e, sizeo|
|00001eb0| 66 28 20 64 6f 75 62 6c | 65 20 29 29 29 29 20 7b |f( doubl|e )))) {|
|00001ec0| 0d 0a 20 20 20 20 20 20 | 70 65 72 72 6f 72 28 22 |.. |perror("|
|00001ed0| 20 56 4d 53 20 63 6f 70 | 79 20 61 6c 6c 6f 63 61 | VMS cop|y alloca|
|00001ee0| 74 69 6f 6e 20 65 72 72 | 6f 72 22 29 3b 0d 0a 20 |tion err|or");.. |
|00001ef0| 20 20 20 20 20 65 78 69 | 74 28 31 29 3b 0d 0a 20 | exi|t(1);.. |
|00001f00| 20 20 20 7d 0d 0a 20 20 | 20 20 77 68 69 6c 65 28 | }.. | while(|
|00001f10| 20 2d 2d 6e 75 6d 65 6c | 65 20 3e 3d 20 30 20 29 | --numel|e >= 0 )|
|00001f20| 20 7b 0d 0a 20 20 20 20 | 20 20 69 66 20 28 20 21 | {.. | if ( !|
|00001f30| 28 70 20 3d 20 28 64 6f | 75 62 6c 65 20 2a 29 20 |(p = (do|uble *) |
|00001f40| 76 72 65 61 64 28 20 76 | 2e 68 64 72 2c 20 6e 75 |vread( v|.hdr, nu|
|00001f50| 6d 65 6c 65 29 29 29 7b | 0d 0a 20 20 20 20 20 20 |mele))){|.. |
|00001f60| 20 20 70 65 72 72 6f 72 | 28 22 56 4d 53 20 63 6f | perror|("VMS co|
|00001f70| 70 79 2d 61 63 63 65 73 | 73 28 20 72 65 61 64 20 |py-acces|s( read |
|00001f80| 29 20 65 72 72 6f 72 22 | 29 3b 0d 0a 20 20 20 20 |) error"|);.. |
|00001f90| 20 20 20 20 65 78 69 74 | 28 31 29 3b 0d 0a 20 20 | exit|(1);.. |
|00001fa0| 20 20 20 20 7d 0d 0a 20 | 20 20 20 20 20 69 66 20 | }.. | if |
|00001fb0| 28 21 76 77 72 69 74 65 | 28 68 64 72 2c 20 6e 75 |(!vwrite|(hdr, nu|
|00001fc0| 6d 65 6c 65 2c 28 63 68 | 61 72 20 2a 29 70 29 29 |mele,(ch|ar *)p))|
|00001fd0| 7b 0d 0a 20 20 20 20 20 | 20 20 20 70 65 72 72 6f |{.. | perro|
|00001fe0| 72 28 22 56 4d 53 20 63 | 6f 70 79 2d 61 63 63 65 |r("VMS c|opy-acce|
|00001ff0| 73 73 28 20 77 72 69 74 | 65 20 29 20 65 72 72 6f |ss( writ|e ) erro|
|00002000| 72 22 29 3b 0d 0a 20 20 | 20 20 20 20 20 20 65 78 |r");.. | ex|
|00002010| 69 74 28 31 29 3b 0d 0a | 20 20 20 20 20 20 7d 0d |it(1);..| }.|
|00002020| 0a 20 20 20 20 7d 0d 0a | 20 20 20 20 72 65 74 75 |. }..| retu|
|00002030| 72 6e 20 2a 63 75 72 5f | 65 6c 65 3b 0d 0a 20 20 |rn *cur_|ele;.. |
|00002040| 7d 0d 0a 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |}..\end{|verbatim|
|00002050| 7d 0d 0a 0d 0a 54 68 69 | 73 20 63 6f 64 65 20 66 |}....Thi|s code f|
|00002060| 72 61 67 6d 65 6e 74 20 | 72 65 61 6c 6c 79 20 65 |ragment |really e|
|00002070| 6d 70 68 61 73 69 7a 65 | 73 20 68 6f 77 20 77 65 |mphasize|s how we|
|00002080| 6c 6c 20 74 68 65 20 76 | 64 6f 75 62 0d 0a 63 6c |ll the v|doub..cl|
|00002090| 61 73 73 20 69 6e 73 75 | 6c 61 74 65 73 20 74 68 |ass insu|lates th|
|000020a0| 65 20 75 73 65 72 20 66 | 72 6f 6d 20 74 68 65 20 |e user f|rom the |
|000020b0| 76 6d 6d 20 73 79 73 74 | 65 6d 2e 20 59 6f 75 20 |vmm syst|em. You |
|000020c0| 64 6f 6e 27 74 0d 0a 68 | 61 76 65 20 74 6f 20 72 |don't..h|ave to r|
|000020d0| 65 6d 65 6d 62 65 72 20 | 61 6c 6c 20 6f 66 20 74 |emember |all of t|
|000020e0| 68 65 20 61 72 67 75 6d | 65 6e 74 73 20 66 6f 72 |he argum|ents for|
|000020f0| 20 76 72 65 61 64 2c 20 | 76 77 72 69 74 65 2c 0d | vread, |vwrite,.|
|00002100| 0a 61 6e 64 20 76 6d 61 | 6c 6c 6f 63 2e 20 59 6f |.and vma|lloc. Yo|
|00002110| 75 20 61 6c 73 6f 20 68 | 61 76 65 20 61 20 67 6f |u also h|ave a go|
|00002120| 6f 64 20 64 65 61 6c 20 | 6f 66 20 65 72 72 6f 72 |od deal |of error|
|00002130| 20 63 68 65 63 6b 69 6e | 67 0d 0a 65 6d 62 65 64 | checkin|g..embed|
|00002140| 64 65 64 20 69 6e 20 74 | 68 65 20 61 73 73 69 67 |ded in t|he assig|
|00002150| 6e 6d 65 6e 74 20 6f 70 | 65 72 61 74 6f 72 73 2e |nment op|erators.|
|00002160| 1a | |. | |
+--------+-------------------------+-------------------------+--------+--------+