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
| LaTeX document text
| default
| |
99%
| 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| 0d 0a 5c 63 68 61 70 74 | 65 72 7b 56 69 72 74 75 |..\chapt|er{Virtu|
|00000010| 61 6c 20 4d 65 6d 6f 72 | 79 20 53 79 73 74 65 6d |al Memor|y System|
|00000020| 7d 0d 0a 0d 0a 54 68 65 | 20 76 69 72 74 75 61 6c |}....The| virtual|
|00000030| 20 6d 65 6d 6f 72 79 20 | 73 79 73 74 65 6d 5c 69 | memory |system\i|
|00000040| 6e 64 65 78 7b 76 6d 6d | 20 7d 20 61 6c 6c 6f 77 |ndex{vmm| } allow|
|00000050| 73 20 74 68 65 20 6d 61 | 74 72 69 78 0d 0a 65 6c |s the ma|trix..el|
|00000060| 65 6d 65 6e 74 73 20 74 | 6f 20 62 65 20 73 74 6f |ements t|o be sto|
|00000070| 72 65 64 20 6f 75 74 73 | 69 64 65 20 6f 66 20 52 |red outs|ide of R|
|00000080| 41 4d 2e 20 54 68 65 20 | 65 78 74 65 72 6e 61 6c |AM. The |external|
|00000090| 20 66 69 6c 65 20 6d 61 | 79 0d 0a 62 65 20 73 74 | file ma|y..be st|
|000000a0| 6f 72 65 64 20 6f 6e 20 | 61 20 68 61 72 64 20 64 |ored on |a hard d|
|000000b0| 72 69 76 65 2c 20 66 6c | 6f 70 70 79 20 64 72 69 |rive, fl|oppy dri|
|000000c0| 76 65 2c 20 6f 72 20 69 | 6e 20 61 20 52 41 4d 20 |ve, or i|n a RAM |
|000000d0| 64 69 73 6b 2e 0d 0a 54 | 68 65 20 52 41 4d 20 64 |disk...T|he RAM d|
|000000e0| 69 73 6b 20 70 72 6f 76 | 69 64 65 73 20 74 68 65 |isk prov|ides the|
|000000f0| 20 66 61 73 74 65 73 74 | 20 61 63 63 65 73 73 20 | fastest| access |
|00000100| 74 6f 20 74 68 65 20 6d | 61 74 72 69 63 65 73 2c |to the m|atrices,|
|00000110| 0d 0a 62 75 74 20 6d 61 | 79 20 62 65 20 6f 66 20 |..but ma|y be of |
|00000120| 6c 69 74 74 6c 65 20 76 | 61 6c 75 65 20 74 6f 20 |little v|alue to |
|00000130| 6d 61 63 68 69 6e 65 73 | 20 77 69 74 68 6f 75 74 |machines| without|
|00000140| 20 61 20 6c 61 72 67 65 | 0d 0a 61 6d 6f 75 6e 74 | a large|..amount|
|00000150| 20 6f 66 20 65 78 74 65 | 6e 64 65 64 20 6d 65 6d | of exte|nded mem|
|00000160| 6f 72 79 2e 20 54 68 65 | 20 6d 61 74 72 69 78 20 |ory. The| matrix |
|00000170| 63 6c 61 73 73 20 73 74 | 6f 72 65 73 20 61 74 20 |class st|ores at |
|00000180| 6d 6f 73 74 0d 0a 36 34 | 20 64 6f 75 62 6c 65 73 |most..64| doubles|
|00000190| 20 69 6e 20 61 20 62 75 | 66 66 65 72 20 69 6e 20 | in a bu|ffer in |
|000001a0| 52 41 4d 2e 20 49 66 20 | 74 68 65 20 72 65 71 75 |RAM. If |the requ|
|000001b0| 65 73 74 65 64 20 65 6c | 65 6d 65 6e 74 20 69 73 |ested el|ement is|
|000001c0| 0d 0a 6e 6f 74 20 69 6e | 20 74 68 65 20 62 75 66 |..not in| the buf|
|000001d0| 66 65 72 2c 20 74 68 65 | 6e 20 74 68 65 20 76 69 |fer, the|n the vi|
|000001e0| 72 74 75 61 6c 20 73 79 | 73 74 65 6d 20 73 65 61 |rtual sy|stem sea|
|000001f0| 72 63 68 65 73 20 74 68 | 65 0d 0a 66 69 6c 65 20 |rches th|e..file |
|00000200| 66 6f 72 20 74 68 65 20 | 62 6c 6f 63 6b 20 63 6f |for the |block co|
|00000210| 6e 74 61 69 6e 69 6e 67 | 20 74 68 65 20 65 6c 65 |ntaining| the ele|
|00000220| 6d 65 6e 74 2e 20 54 68 | 65 20 76 69 72 74 75 61 |ment. Th|e virtua|
|00000230| 6c 0d 0a 73 79 73 74 65 | 6d 20 74 68 65 6e 20 70 |l..syste|m then p|
|00000240| 61 67 65 73 20 74 68 65 | 20 72 65 71 75 65 73 74 |ages the| request|
|00000250| 65 64 20 62 6c 6f 63 6b | 20 69 6e 74 6f 20 74 68 |ed block| into th|
|00000260| 65 20 6d 61 74 72 69 78 | 0d 0a 62 75 66 66 65 72 |e matrix|..buffer|
|00000270| 2e 0d 0a 0d 0a 54 68 65 | 20 61 6c 67 6f 72 69 74 |.....The| algorit|
|00000280| 68 6d 20 66 6f 72 20 61 | 6c 6c 6f 63 61 74 69 6e |hm for a|llocatin|
|00000290| 67 20 6d 65 6d 6f 72 79 | 20 69 73 20 66 6f 75 6e |g memory| is foun|
|000002a0| 64 20 69 6e 20 4b 65 72 | 6e 69 67 68 61 6e 0d 0a |d in Ker|nighan..|
|000002b0| 61 6e 64 20 52 69 74 63 | 68 69 65 5c 63 69 74 65 |and Ritc|hie\cite|
|000002c0| 7b 6b 72 3a 63 70 72 67 | 7d 2e 20 48 6f 6c 75 62 |{kr:cprg|}. Holub|
|000002d0| 5c 63 69 74 65 7b 48 6f | 3a 70 72 7d 20 61 64 61 |\cite{Ho|:pr} ada|
|000002e0| 70 74 65 64 20 74 68 65 | 0d 0a 61 6c 67 6f 72 69 |pted the|..algori|
|000002f0| 74 68 6d 20 66 6f 72 20 | 6d 61 6e 61 67 69 6e 67 |thm for |managing|
|00000300| 20 74 68 65 20 64 61 74 | 61 20 69 6e 20 76 69 72 | the dat|a in vir|
|00000310| 74 75 61 6c 20 6d 65 6d | 6f 72 79 20 66 69 6c 65 |tual mem|ory file|
|00000320| 0d 0a 28 69 6e 73 74 65 | 61 64 20 6f 66 20 64 61 |..(inste|ad of da|
|00000330| 74 61 20 6f 6e 20 74 68 | 65 20 68 65 61 70 29 2e |ta on th|e heap).|
|00000340| 20 48 6f 6c 75 62 27 73 | 20 70 72 6f 67 72 61 6d | Holub's| program|
|00000350| 20 77 61 73 0d 0a 6d 6f | 64 69 66 69 65 64 20 74 | was..mo|dified t|
|00000360| 6f 20 63 6f 6d 70 69 6c | 65 20 69 6e 20 54 75 72 |o compil|e in Tur|
|00000370| 62 6f 20 43 2b 2b 2c 20 | 61 6e 64 20 73 6f 6d 65 |bo C++, |and some|
|00000380| 20 62 75 67 73 20 77 65 | 72 65 0d 0a 63 6f 72 72 | bugs we|re..corr|
|00000390| 65 63 74 65 64 2e 20 48 | 6f 6c 75 62 20 74 68 65 |ected. H|olub the|
|000003a0| 6e 20 63 6f 6e 73 74 72 | 75 63 74 65 64 20 61 20 |n constr|ucted a |
|000003b0| 63 6c 61 73 73 20 66 6f | 72 20 69 6e 74 65 67 65 |class fo|r intege|
|000003c0| 72 0d 0a 76 65 63 74 6f | 72 73 20 73 74 6f 72 65 |r..vecto|rs store|
|000003d0| 64 20 69 6e 20 76 69 72 | 74 75 61 6c 20 6d 65 6d |d in vir|tual mem|
|000003e0| 6f 72 79 2e 20 54 68 69 | 73 20 63 6c 61 73 73 20 |ory. Thi|s class |
|000003f0| 77 61 73 20 61 64 61 70 | 74 65 64 20 74 6f 0d 0a |was adap|ted to..|
|00000400| 64 6f 75 62 6c 65 73 2c | 20 61 6e 64 20 74 68 65 |doubles,| and the|
|00000410| 20 6d 61 74 72 69 78 20 | 63 6c 61 73 73 20 77 61 | matrix |class wa|
|00000420| 73 20 63 6f 6e 73 74 72 | 75 63 74 65 64 20 62 79 |s constr|ucted by|
|00000430| 0d 0a 64 65 72 65 66 65 | 72 65 6e 63 69 6e 67 20 |..derefe|rencing |
|00000440| 6d 61 74 72 69 78 20 65 | 6c 65 6d 65 6e 74 73 20 |matrix e|lements |
|00000450| 73 74 6f 72 65 64 20 69 | 6e 20 74 68 65 20 76 69 |stored i|n the vi|
|00000460| 72 74 75 61 6c 20 76 65 | 63 74 6f 72 0d 0a 69 6e |rtual ve|ctor..in|
|00000470| 20 72 6f 77 20 6d 61 6a | 6f 72 20 6f 72 64 65 72 | row maj|or order|
|00000480| 2e 20 54 68 65 20 6d 61 | 74 72 69 78 20 63 6c 61 |. The ma|trix cla|
|00000490| 73 73 2c 20 56 4d 61 74 | 72 69 78 2c 20 77 69 6c |ss, VMat|rix, wil|
|000004a0| 6c 20 62 65 0d 0a 64 65 | 73 63 72 69 62 65 64 20 |l be..de|scribed |
|000004b0| 6c 61 74 65 72 2e 20 0d | 0a 0d 0a 54 68 69 73 20 |later. .|...This |
|000004c0| 63 68 61 70 74 65 72 20 | 77 69 6c 6c 20 67 69 76 |chapter |will giv|
|000004d0| 65 20 61 20 6c 6f 6f 73 | 65 20 65 78 70 6c 61 6e |e a loos|e explan|
|000004e0| 61 74 69 6f 6e 20 6f 66 | 20 74 68 65 20 76 69 72 |ation of| the vir|
|000004f0| 74 75 61 6c 0d 0a 6d 65 | 6d 6f 72 79 20 73 79 73 |tual..me|mory sys|
|00000500| 74 65 6d 2e 20 49 74 20 | 77 69 6c 6c 20 63 6f 6e |tem. It |will con|
|00000510| 63 65 6e 74 72 61 74 65 | 20 6f 6e 20 74 68 65 20 |centrate| on the |
|00000520| 70 75 62 6c 69 63 20 66 | 75 6e 63 74 69 6f 6e 73 |public f|unctions|
|00000530| 0d 0a 69 6e 20 48 6f 6c | 75 62 27 73 20 77 6f 72 |..in Hol|ub's wor|
|00000540| 6b 2e 20 54 68 65 20 72 | 65 61 64 65 72 20 77 68 |k. The r|eader wh|
|00000550| 6f 20 69 73 20 69 6e 74 | 65 72 65 73 74 65 64 20 |o is int|erested |
|00000560| 69 6e 20 75 73 69 6e 67 | 0d 0a 74 68 65 73 65 20 |in using|..these |
|00000570| 66 75 6e 63 74 69 6f 6e | 73 20 73 68 6f 75 6c 64 |function|s should|
|00000580| 20 6f 62 74 61 69 6e 20 | 61 20 63 6f 70 79 20 6f | obtain |a copy o|
|00000590| 66 20 74 68 65 20 61 72 | 74 69 63 6c 65 2c 20 61 |f the ar|ticle, a|
|000005a0| 6e 64 0d 0a 77 6f 72 6b | 20 74 68 72 6f 75 67 68 |nd..work| through|
|000005b0| 20 74 68 65 20 70 72 6f | 67 72 61 6d 20 5c 66 6f | the pro|gram \fo|
|000005c0| 6f 74 6e 6f 74 65 7b 54 | 79 70 65 20 69 74 20 69 |otnote{T|ype it i|
|000005d0| 6e 20 61 6e 64 0d 0a 63 | 6f 6d 70 72 65 68 65 6e |n and..c|omprehen|
|000005e0| 64 20 74 68 65 20 63 6f | 6d 6d 65 6e 74 73 2e 20 |d the co|mments. |
|000005f0| 49 20 74 6f 6f 6b 20 74 | 68 72 65 65 20 77 65 65 |I took t|hree wee|
|00000600| 6b 73 20 6f 66 20 73 70 | 61 72 65 0d 0a 74 69 6d |ks of sp|are..tim|
|00000610| 65 2e 7d 2e 20 54 68 65 | 72 65 20 61 72 65 20 73 |e.}. The|re are s|
|00000620| 6f 6d 65 20 73 70 61 72 | 6b 73 20 69 6e 20 69 74 |ome spar|ks in it|
|00000630| 2e 0d 0a 0d 0a 48 6f 77 | 65 76 65 72 2c 20 74 68 |.....How|ever, th|
|00000640| 65 73 65 20 66 75 6e 63 | 74 69 6f 6e 73 20 61 72 |ese func|tions ar|
|00000650| 65 20 66 72 61 67 69 6c | 65 2c 20 73 6f 20 69 74 |e fragil|e, so it|
|00000660| 20 69 73 20 6e 6f 74 0d | 0a 72 65 63 6f 6d 6d 65 | is not.|.recomme|
|00000670| 6e 64 65 64 20 74 68 61 | 74 20 74 68 65 79 20 62 |nded tha|t they b|
|00000680| 65 20 75 73 65 64 20 64 | 69 72 65 63 74 6c 79 20 |e used d|irectly |
|00000690| 69 6e 20 61 6e 79 20 70 | 72 6f 67 72 61 6d 20 66 |in any p|rogram f|
|000006a0| 6f 72 0d 0a 74 68 65 20 | 76 69 72 74 75 61 6c 20 |or..the |virtual |
|000006b0| 6d 61 74 72 69 78 20 61 | 70 70 6c 69 63 61 74 69 |matrix a|pplicati|
|000006c0| 6f 6e 73 2e 20 54 68 65 | 20 76 69 72 74 75 61 6c |ons. The| virtual|
|000006d0| 20 6d 65 6d 6f 72 79 0d | 0a 66 75 6e 63 74 69 6f | memory.|.functio|
|000006e0| 6e 73 20 73 68 6f 75 6c | 64 20 62 65 20 63 6f 6e |ns shoul|d be con|
|000006f0| 73 69 64 65 72 65 64 20 | 65 6e 63 61 70 73 75 6c |sidered |encapsul|
|00000700| 61 74 65 64 20 69 6e 20 | 74 68 65 20 6d 61 74 72 |ated in |the matr|
|00000710| 69 78 0d 0a 61 6c 67 6f | 72 69 74 68 6d 73 2e 20 |ix..algo|rithms. |
|00000720| 54 68 65 20 6d 61 74 72 | 69 78 20 63 6c 61 73 73 |The matr|ix class|
|00000730| 20 66 72 65 65 73 20 74 | 68 65 20 75 73 65 72 20 | frees t|he user |
|00000740| 6f 66 20 74 68 65 20 6f | 76 65 72 68 65 61 64 0d |of the o|verhead.|
|00000750| 0a 6f 66 20 64 69 72 65 | 63 74 6c 79 20 6d 61 6e |.of dire|ctly man|
|00000760| 69 70 75 6c 61 74 69 6e | 67 20 74 68 65 20 76 69 |ipulatin|g the vi|
|00000770| 72 74 75 61 6c 20 6d 65 | 6d 6f 72 79 2e 0d 0a 0d |rtual me|mory....|
|00000780| 0a 49 66 20 79 6f 75 20 | 61 72 65 20 75 73 69 6e |.If you |are usin|
|00000790| 67 20 74 68 65 20 69 6e | 2d 72 61 6d 20 76 65 72 |g the in|-ram ver|
|000007a0| 73 69 6f 6e 2c 20 79 6f | 75 20 63 61 6e 20 73 6b |sion, yo|u can sk|
|000007b0| 69 70 20 74 68 69 73 20 | 63 68 61 70 74 65 72 0d |ip this |chapter.|
|000007c0| 0a 73 69 6e 63 65 20 6d | 61 74 72 69 63 65 73 20 |.since m|atrices |
|000007d0| 61 72 65 20 61 6c 6c 6f | 63 61 74 65 64 20 66 72 |are allo|cated fr|
|000007e0| 6f 6d 20 74 68 65 20 68 | 65 61 70 20 75 73 69 6e |om the h|eap usin|
|000007f0| 67 20 63 61 6c 6c 6f 63 | 28 29 2e 0d 0a 0d 0a 5c |g calloc|().....\|
|00000800| 73 65 63 74 69 6f 6e 7b | 76 6d 65 6d 20 61 6e 64 |section{|vmem and|
|00000810| 20 68 64 72 7d 0d 0a 0d | 0a 54 68 65 20 76 69 72 | hdr}...|.The vir|
|00000820| 74 75 61 6c 20 6d 65 6d | 6f 72 79 20 73 79 73 74 |tual mem|ory syst|
|00000830| 65 6d 20 28 76 6d 6d 29 | 20 69 73 20 64 72 69 76 |em (vmm)| is driv|
|00000840| 65 6e 20 6f 66 66 20 74 | 68 65 20 66 6f 6c 6c 6f |en off t|he follo|
|00000850| 77 69 6e 67 0d 0a 74 77 | 6f 20 73 74 72 75 63 74 |wing..tw|o struct|
|00000860| 75 72 65 73 3a 0d 0a 0d | 0a 5c 62 65 67 69 6e 7b |ures:...|.\begin{|
|00000870| 76 65 72 62 61 74 69 6d | 7d 0d 0a 74 79 70 65 64 |verbatim|}..typed|
|00000880| 65 66 20 73 74 72 75 63 | 74 20 76 6d 65 6d 7b 0d |ef struc|t vmem{.|
|00000890| 0a 20 20 75 6e 73 69 67 | 6e 65 64 20 73 69 67 6e |. unsig|ned sign|
|000008a0| 61 74 75 72 65 3b 0d 0a | 20 20 75 6e 73 69 67 6e |ature;..| unsign|
|000008b0| 65 64 20 64 69 72 74 79 | 3b 0d 0a 20 20 75 6e 73 |ed dirty|;.. uns|
|000008c0| 69 67 6e 65 64 20 65 6c | 65 5f 73 69 7a 65 3b 0d |igned el|e_size;.|
|000008d0| 0a 20 20 75 6e 73 69 67 | 6e 65 64 20 65 6c 65 5f |. unsig|ned ele_|
|000008e0| 70 65 72 5f 62 6c 6b 3b | 0d 0a 20 20 6c 6f 6e 67 |per_blk;|.. long|
|000008f0| 20 6e 75 6d 5f 65 6c 65 | 3b 0d 0a 20 20 75 6e 73 | num_ele|;.. uns|
|00000900| 69 67 6e 65 64 20 63 62 | 6c 6f 63 6b 3b 0d 0a 20 |igned cb|lock;.. |
|00000910| 20 63 68 61 72 20 2a 62 | 75 66 3b 0d 0a 7d 20 76 | char *b|uf;..} v|
|00000920| 6d 65 6d 3b 0d 0a 0d 0a | 74 79 70 65 64 65 66 20 |mem;....|typedef |
|00000930| 73 74 72 75 63 74 20 68 | 64 72 20 7b 0d 0a 20 20 |struct h|dr {.. |
|00000940| 69 6e 74 20 61 63 74 69 | 76 65 3b 0d 0a 20 20 69 |int acti|ve;.. i|
|00000950| 6e 74 20 6e 72 65 66 73 | 3b 0d 0a 20 20 75 6e 73 |nt nrefs|;.. uns|
|00000960| 69 67 6e 65 64 20 6e 62 | 6c 6f 63 6b 73 3b 0d 0a |igned nb|locks;..|
|00000970| 20 20 75 6e 73 69 67 6e | 65 64 20 6f 66 66 73 65 | unsign|ed offse|
|00000980| 74 3b 0d 0a 20 20 75 6e | 69 6f 6e 20 7b 20 73 74 |t;.. un|ion { st|
|00000990| 72 75 63 74 20 68 64 72 | 20 2a 68 3b 20 2f 2f 69 |ruct hdr| *h; //i|
|000009a0| 66 20 68 64 72 20 69 73 | 20 69 6e 20 66 72 65 65 |f hdr is| in free|
|000009b0| 6c 69 73 74 20 28 61 63 | 74 69 76 65 3d 30 29 0d |list (ac|tive=0).|
|000009c0| 0a 20 20 20 20 20 20 20 | 20 73 74 72 75 63 74 20 |. | struct |
|000009d0| 76 6d 65 6d 20 2a 76 3b | 20 20 2f 2f 76 69 72 74 |vmem *v;| //virt|
|000009e0| 2e 20 6d 65 6d 2e 20 65 | 6c 65 6d 65 6e 74 20 28 |. mem. e|lement (|
|000009f0| 61 63 74 69 76 65 20 3d | 20 31 29 0d 0a 20 20 7d |active =| 1).. }|
|00000a00| 20 6e 65 78 74 3b 0d 0a | 7d 20 68 64 72 3b 0d 0a | next;..|} hdr;..|
|00000a10| 0d 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d |..\end{v|erbatim}|
|00000a20| 0d 0a 0d 0a 49 74 20 68 | 65 6c 70 73 20 74 6f 20 |....It h|elps to |
|00000a30| 74 68 69 6e 6b 20 6f 66 | 20 74 68 65 20 76 69 72 |think of| the vir|
|00000a40| 74 75 61 6c 20 6d 65 6d | 6f 72 79 20 66 69 6c 65 |tual mem|ory file|
|00000a50| 20 61 73 20 61 20 6c 6f | 6e 67 0d 0a 61 72 72 61 | as a lo|ng..arra|
|00000a60| 79 20 6f 66 20 75 6e 73 | 69 67 6e 65 64 20 63 68 |y of uns|igned ch|
|00000a70| 61 72 73 2e 20 54 68 65 | 20 68 64 72 20 73 74 72 |ars. The| hdr str|
|00000a80| 75 63 74 75 72 65 20 70 | 6f 69 6e 74 73 20 74 6f |ucture p|oints to|
|00000a90| 20 61 0d 0a 72 65 67 69 | 6f 6e 20 69 6e 20 74 68 | a..regi|on in th|
|00000aa0| 65 20 66 69 6c 65 2e 20 | 54 68 65 20 72 65 67 69 |e file. |The regi|
|00000ab0| 6f 6e 20 6d 61 79 20 62 | 65 20 75 73 65 64 20 6f |on may b|e used o|
|00000ac0| 72 20 66 72 65 65 20 66 | 6f 72 20 75 73 65 2e 0d |r free f|or use..|
|00000ad0| 0a 54 68 65 20 75 73 65 | 64 20 72 65 67 69 6f 6e |.The use|d region|
|00000ae0| 73 20 6f 66 20 74 68 65 | 20 66 69 6c 65 20 61 72 |s of the| file ar|
|00000af0| 65 20 72 65 66 65 72 65 | 6e 63 65 64 20 62 79 20 |e refere|nced by |
|00000b00| 61 20 76 6d 65 6d 0d 0a | 73 74 72 75 63 74 75 72 |a vmem..|structur|
|00000b10| 65 2e 20 54 68 65 20 75 | 6e 75 73 65 64 20 72 65 |e. The u|nused re|
|00000b20| 67 69 6f 6e 73 20 61 72 | 65 20 6b 65 70 74 20 69 |gions ar|e kept i|
|00000b30| 6e 20 61 20 63 69 72 63 | 75 6c 61 72 20 6c 69 6e |n a circ|ular lin|
|00000b40| 6b 65 64 0d 0a 6c 69 73 | 74 20 6f 66 20 68 65 61 |ked..lis|t of hea|
|00000b50| 64 65 72 73 2e 20 54 68 | 65 73 65 20 73 74 72 75 |ders. Th|ese stru|
|00000b60| 63 74 75 72 65 73 20 61 | 72 65 20 64 65 73 63 72 |ctures a|re descr|
|00000b70| 69 62 65 64 20 69 6e 20 | 4b 65 72 6e 69 67 68 61 |ibed in |Kernigha|
|00000b80| 6e 0d 0a 61 6e 64 20 52 | 69 74 63 68 69 65 2e 20 |n..and R|itchie. |
|00000b90| 54 68 65 20 65 6c 65 6d | 65 6e 74 73 20 6f 66 20 |The elem|ents of |
|00000ba0| 74 68 65 20 68 64 72 20 | 73 74 72 75 63 74 75 72 |the hdr |structur|
|00000bb0| 65 20 61 72 65 3a 0d 0a | 5c 62 65 67 69 6e 7b 64 |e are:..|\begin{d|
|00000bc0| 65 73 63 72 69 70 74 69 | 6f 6e 7d 0d 0a 20 20 5c |escripti|on}.. \|
|00000bd0| 69 74 65 6d 5b 61 63 74 | 69 76 65 5d 20 41 6e 20 |item[act|ive] An |
|00000be0| 69 6e 64 69 63 61 74 6f | 72 20 74 68 61 74 20 74 |indicato|r that t|
|00000bf0| 68 65 20 68 65 61 64 65 | 72 20 70 6f 69 6e 74 73 |he heade|r points|
|00000c00| 20 74 6f 20 61 0d 0a 20 | 20 20 20 20 20 20 20 20 | to a.. | |
|00000c10| 20 20 20 20 20 20 20 76 | 6d 65 6d 20 28 31 29 20 | v|mem (1) |
|00000c20| 6f 72 20 69 73 20 69 6e | 20 74 68 65 20 66 72 65 |or is in| the fre|
|00000c30| 65 6c 69 73 74 20 28 30 | 29 2e 20 49 74 20 69 73 |elist (0|). It is|
|00000c40| 0d 0a 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |.. | |
|00000c50| 20 20 75 73 65 64 20 66 | 6f 72 20 65 72 72 6f 72 | used f|or error|
|00000c60| 20 74 72 61 70 70 69 6e | 67 20 61 6e 64 20 64 65 | trappin|g and de|
|00000c70| 62 75 67 67 69 6e 67 2e | 0d 0a 20 20 5c 69 74 65 |bugging.|.. \ite|
|00000c80| 6d 5b 6e 72 65 66 73 5d | 20 49 6e 64 69 63 61 74 |m[nrefs]| Indicat|
|00000c90| 6f 72 20 66 6f 72 20 74 | 68 65 20 6e 75 6d 62 65 |or for t|he numbe|
|00000ca0| 72 20 6f 66 20 6d 61 74 | 72 69 63 65 73 20 75 73 |r of mat|rices us|
|00000cb0| 69 6e 67 20 0d 0a 20 20 | 20 20 20 20 20 20 20 20 |ing .. | |
|00000cc0| 20 20 20 20 20 20 74 68 | 69 73 20 68 64 72 2e 20 | th|is hdr. |
|00000cd0| 53 65 65 20 74 68 65 20 | 63 68 61 70 74 65 72 20 |See the |chapter |
|00000ce0| 6f 6e 20 74 68 65 20 73 | 74 61 63 6b 20 66 6f 72 |on the s|tack for|
|00000cf0| 0d 0a 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |.. | |
|00000d00| 20 20 68 6f 77 20 74 68 | 69 73 20 76 61 72 69 61 | how th|is varia|
|00000d10| 62 6c 65 20 69 73 20 75 | 73 65 64 2e 20 20 0d 0a |ble is u|sed. ..|
|00000d20| 20 20 5c 69 74 65 6d 5b | 6e 62 6c 6f 63 6b 73 5d | \item[|nblocks]|
|00000d30| 20 6e 75 6d 62 65 72 20 | 6f 66 20 62 6c 6f 63 6b | number |of block|
|00000d40| 73 20 70 6f 69 6e 74 65 | 64 20 74 6f 20 62 79 20 |s pointe|d to by |
|00000d50| 74 68 65 20 68 64 72 0d | 0a 20 20 5c 69 74 65 6d |the hdr.|. \item|
|00000d60| 5b 6f 66 66 73 65 74 5d | 20 20 74 68 65 20 6f 66 |[offset]| the of|
|00000d70| 66 73 65 74 20 69 6e 20 | 74 68 65 20 76 69 72 74 |fset in |the virt|
|00000d80| 75 61 6c 20 66 69 6c 65 | 20 6f 66 20 74 68 65 0d |ual file| of the.|
|00000d90| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |. | |
|00000da0| 20 20 66 69 72 73 74 20 | 62 6c 6f 63 6b 20 70 6f | first |block po|
|00000db0| 69 6e 74 65 64 20 74 6f | 2e 20 0d 0a 20 20 5c 69 |inted to|. .. \i|
|00000dc0| 74 65 6d 5b 6e 65 78 74 | 5d 20 20 54 68 65 20 6e |tem[next|] The n|
|00000dd0| 65 78 74 20 68 65 61 64 | 65 72 20 69 6e 20 74 68 |ext head|er in th|
|00000de0| 65 20 66 72 65 65 6c 69 | 73 74 2c 20 6f 72 20 74 |e freeli|st, or t|
|00000df0| 68 65 20 76 6d 65 6d 0d | 0a 20 20 20 20 20 20 20 |he vmem.|. |
|00000e00| 20 20 20 20 20 20 20 20 | 62 65 69 6e 67 20 70 6f | |being po|
|00000e10| 69 6e 74 65 64 20 74 6f | 0d 0a 5c 65 6e 64 7b 64 |inted to|..\end{d|
|00000e20| 65 73 63 72 69 70 74 69 | 6f 6e 7d 0d 0a 54 68 65 |escripti|on}..The|
|00000e30| 20 68 64 72 20 69 73 20 | 61 6e 61 6c 6f 67 6f 75 | hdr is |analogou|
|00000e40| 73 20 74 6f 20 61 20 70 | 6f 69 6e 74 65 72 20 72 |s to a p|ointer r|
|00000e50| 65 74 75 72 6e 65 64 20 | 62 79 20 6d 61 6c 6c 6f |eturned |by mallo|
|00000e60| 63 28 29 20 6f 66 0d 0a | 66 72 65 65 64 20 62 79 |c() of..|freed by|
|00000e70| 20 66 72 65 65 28 29 2e | 0d 0a 0d 0a 54 68 65 20 | free().|....The |
|00000e80| 76 6d 65 6d 20 73 74 72 | 75 63 74 75 72 65 20 63 |vmem str|ucture c|
|00000e90| 6f 6e 74 61 69 6e 73 20 | 74 68 65 20 69 6e 66 6f |ontains |the info|
|00000ea0| 72 6d 61 74 69 6f 6e 20 | 66 6f 72 20 61 6e 20 61 |rmation |for an a|
|00000eb0| 63 74 69 76 65 0d 0a 68 | 64 72 2e 20 54 68 65 20 |ctive..h|dr. The |
|00000ec0| 76 6d 6d 20 66 69 6c 65 | 20 69 73 20 6f 72 67 61 |vmm file| is orga|
|00000ed0| 6e 69 7a 65 64 20 69 6e | 20 62 6c 6f 63 6b 73 20 |nized in| blocks |
|00000ee0| 6f 66 20 73 69 7a 65 0d | 0a 42 4c 4b 5c 5f 53 49 |of size.|.BLK\_SI|
|00000ef0| 5a 45 2e 20 5c 66 6f 6f | 74 6e 6f 74 65 7b 54 68 |ZE. \foo|tnote{Th|
|00000f00| 65 20 62 6c 6f 63 6b 20 | 73 69 7a 65 20 69 73 20 |e block |size is |
|00000f10| 35 31 32 20 66 6f 72 20 | 61 20 56 4d 61 74 72 69 |512 for |a VMatri|
|00000f20| 78 2e 0d 0a 54 68 69 73 | 20 61 6c 6c 6f 77 73 20 |x...This| allows |
|00000f30| 61 20 33 32 20 6d 65 67 | 20 6d 65 6d 6f 72 79 20 |a 32 meg| memory |
|00000f40| 62 75 66 66 65 72 7d 0d | 0a 54 68 65 20 65 6c 65 |buffer}.|.The ele|
|00000f50| 6d 65 6e 74 73 20 6f 66 | 20 74 68 65 20 76 6d 65 |ments of| the vme|
|00000f60| 6d 20 61 72 65 3a 0d 0a | 5c 62 65 67 69 6e 7b 64 |m are:..|\begin{d|
|00000f70| 65 73 63 72 69 70 74 69 | 6f 6e 7d 0d 0a 20 20 5c |escripti|on}.. \|
|00000f80| 69 74 65 6d 5b 73 69 67 | 6e 61 74 75 72 65 5d 20 |item[sig|nature] |
|00000f90| 61 6e 20 69 6e 64 69 63 | 61 74 6f 72 20 74 68 61 |an indic|ator tha|
|00000fa0| 74 20 74 68 65 20 6d 61 | 74 72 69 78 20 68 61 73 |t the ma|trix has|
|00000fb0| 20 6e 6f 74 0d 0a 20 20 | 20 20 20 20 20 20 20 20 | not.. | |
|00000fc0| 20 20 20 20 20 20 20 20 | 20 62 65 65 6e 20 63 6f | | been co|
|00000fd0| 72 72 75 70 74 65 64 20 | 62 79 20 68 65 61 70 20 |rrupted |by heap |
|00000fe0| 6f 76 65 72 77 72 69 74 | 65 73 2e 20 49 74 0d 0a |overwrit|es. It..|
|00000ff0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001000| 20 20 20 69 73 20 30 78 | 35 61 35 61 20 77 68 65 | is 0x|5a5a whe|
|00001010| 6e 20 61 63 74 69 76 65 | 2c 20 61 6e 64 20 73 65 |n active|, and se|
|00001020| 74 20 74 6f 20 7a 65 72 | 6f 0d 0a 20 20 20 20 20 |t to zer|o.. |
|00001030| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 77 68 | | wh|
|00001040| 65 6e 20 69 74 20 69 73 | 20 66 72 65 65 64 2e 20 |en it is| freed. |
|00001050| 54 68 69 73 20 6c 65 61 | 76 65 73 20 61 20 7a 65 |This lea|ves a ze|
|00001060| 72 6f 20 6f 6e 0d 0a 20 | 20 20 20 20 20 20 20 20 |ro on.. | |
|00001070| 20 20 20 20 20 20 20 20 | 20 20 74 68 65 20 68 65 | | the he|
|00001080| 61 70 20 69 6e 20 63 61 | 73 65 20 74 68 65 20 66 |ap in ca|se the f|
|00001090| 72 65 65 64 20 70 6f 69 | 6e 74 65 72 20 69 73 20 |reed poi|nter is |
|000010a0| 72 65 66 65 72 65 6e 63 | 65 64 2e 0d 0a 20 20 5c |referenc|ed... \|
|000010b0| 69 74 65 6d 5b 64 69 72 | 74 79 5d 20 41 6e 20 69 |item[dir|ty] An i|
|000010c0| 6e 64 69 63 61 74 6f 72 | 20 74 68 61 74 20 61 6e |ndicator| that an|
|000010d0| 20 65 6c 65 6d 65 6e 74 | 20 69 6e 20 74 68 65 20 | element| in the |
|000010e0| 70 61 67 65 0d 0a 20 20 | 20 20 20 20 20 20 20 20 |page.. | |
|000010f0| 20 20 20 20 20 62 75 66 | 66 65 72 20 68 61 73 20 | buf|fer has |
|00001100| 62 65 65 6e 20 63 68 61 | 6e 67 65 64 2e 20 49 66 |been cha|nged. If|
|00001110| 20 74 68 69 73 20 66 6c | 61 67 20 69 73 0d 0a 20 | this fl|ag is.. |
|00001120| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 73 65 | | se|
|00001130| 74 2c 20 74 68 65 6e 20 | 77 72 69 74 65 20 74 68 |t, then |write th|
|00001140| 65 20 62 75 66 66 65 72 | 20 6f 75 74 20 74 6f 20 |e buffer| out to |
|00001150| 64 69 73 6b 0d 0a 20 20 | 20 20 20 20 20 20 20 20 |disk.. | |
|00001160| 20 20 20 20 20 62 65 66 | 6f 72 65 20 72 65 61 64 | bef|ore read|
|00001170| 69 6e 67 20 69 6e 20 61 | 20 6e 65 77 20 70 61 67 |ing in a| new pag|
|00001180| 65 2e 0d 0a 20 20 5c 69 | 74 65 6d 5b 65 6c 65 5c |e... \i|tem[ele\|
|00001190| 5f 73 69 7a 65 5d 20 73 | 69 7a 65 20 69 6e 20 62 |_size] s|ize in b|
|000011a0| 79 74 65 73 20 6f 66 20 | 61 6e 20 65 6c 65 6d 65 |ytes of |an eleme|
|000011b0| 6e 74 20 62 65 69 6e 67 | 20 73 74 6f 72 65 64 0d |nt being| stored.|
|000011c0| 0a 20 20 5c 69 74 65 6d | 5b 65 6c 65 5c 5f 70 65 |. \item|[ele\_pe|
|000011d0| 72 5c 5f 62 6c 6f 63 6b | 5d 20 6e 75 6d 62 65 72 |r\_block|] number|
|000011e0| 20 6f 66 20 65 6c 65 6d | 65 6e 74 73 20 70 65 72 | of elem|ents per|
|000011f0| 20 62 6c 6f 63 6b 0d 0a | 20 20 5c 69 74 65 6d 5b | block..| \item[|
|00001200| 6e 75 6d 5c 5f 65 6c 65 | 5d 20 6e 75 6d 62 65 72 |num\_ele|] number|
|00001210| 20 6f 66 20 65 6c 65 6d | 65 6e 74 73 20 70 6f 69 | of elem|ents poi|
|00001220| 6e 74 65 64 20 74 6f 0d | 0a 20 20 5c 69 74 65 6d |nted to.|. \item|
|00001230| 5b 63 62 6c 6f 63 6b 5d | 20 62 6c 6f 63 6b 20 63 |[cblock]| block c|
|00001240| 75 72 72 65 6e 74 6c 79 | 20 69 6e 20 62 75 66 66 |urrently| in buff|
|00001250| 65 72 0d 0a 20 20 5c 69 | 74 65 6d 5b 62 75 66 5d |er.. \i|tem[buf]|
|00001260| 20 61 20 70 6f 69 6e 74 | 65 72 20 74 6f 20 74 68 | a point|er to th|
|00001270| 65 20 70 61 67 65 20 62 | 75 66 66 65 72 2e 0d 0a |e page b|uffer...|
|00001280| 5c 65 6e 64 7b 64 65 73 | 63 72 69 70 74 69 6f 6e |\end{des|cription|
|00001290| 7d 0d 0a 0d 0a 54 68 65 | 20 66 75 6e 63 74 69 6f |}....The| functio|
|000012a0| 6e 20 76 6d 61 6c 6c 6f | 63 28 29 20 63 72 65 61 |n vmallo|c() crea|
|000012b0| 74 65 73 20 61 20 68 64 | 72 20 61 6e 64 20 61 20 |tes a hd|r and a |
|000012c0| 76 6d 65 6d 2e 20 54 68 | 65 0d 0a 66 75 6e 63 74 |vmem. Th|e..funct|
|000012d0| 69 6f 6e 20 76 66 72 65 | 65 28 29 20 66 72 65 65 |ion vfre|e() free|
|000012e0| 73 20 74 68 65 20 76 6d | 65 6d 20 61 6e 64 20 70 |s the vm|em and p|
|000012f0| 6c 61 63 65 73 20 74 68 | 65 20 68 64 72 20 69 6e |laces th|e hdr in|
|00001300| 20 74 68 65 0d 0a 66 72 | 65 65 6c 69 73 74 2e 20 | the..fr|eelist. |
|00001310| 46 72 65 65 64 20 73 70 | 61 63 65 20 69 6e 20 74 |Freed sp|ace in t|
|00001320| 68 65 20 66 69 6c 65 20 | 69 73 20 63 6f 61 6c 65 |he file |is coale|
|00001330| 73 63 65 64 20 77 69 74 | 68 0d 0a 6e 65 69 67 68 |sced wit|h..neigh|
|00001340| 62 6f 72 69 6e 67 20 66 | 72 65 65 20 62 6c 6f 63 |boring f|ree bloc|
|00001350| 6b 73 2e 20 20 20 0d 0a | 0d 0a 5c 73 65 63 74 69 |ks. ..|..\secti|
|00001360| 6f 6e 7b 76 6f 70 65 6e | 28 29 20 61 6e 64 20 76 |on{vopen|() and v|
|00001370| 63 6c 6f 73 65 28 29 7d | 0d 0a 0d 0a 54 68 65 20 |close()}|....The |
|00001380| 66 75 6e 63 74 69 6f 6e | 20 76 6f 70 65 6e 28 29 |function| vopen()|
|00001390| 5c 69 6e 64 65 78 7b 76 | 6d 6d 21 76 6f 70 65 6e |\index{v|mm!vopen|
|000013a0| 28 29 7d 20 69 6e 69 74 | 69 61 6c 69 7a 65 73 20 |()} init|ializes |
|000013b0| 74 68 65 20 76 6d 6d 0d | 0a 73 79 73 74 65 6d 2e |the vmm.|.system.|
|000013c0| 20 54 68 65 20 66 69 6c | 65 20 5c 24 5c 24 5c 24 | The fil|e \$\$\$|
|000013d0| 5c 24 76 6d 65 6d 2e 74 | 6d 70 20 69 73 20 63 72 |\$vmem.t|mp is cr|
|000013e0| 65 61 74 65 64 20 6f 6e | 20 61 20 64 69 73 6b 2e |eated on| a disk.|
|000013f0| 0d 0a 54 68 69 73 20 69 | 73 20 74 68 65 20 74 65 |..This i|s the te|
|00001400| 6d 70 6f 72 61 72 79 20 | 6d 65 6d 6f 72 79 20 66 |mporary |memory f|
|00001410| 69 6c 65 20 77 68 65 72 | 65 20 74 68 65 20 6d 61 |ile wher|e the ma|
|00001420| 74 72 69 63 65 73 20 61 | 72 65 0d 0a 73 74 6f 72 |trices a|re..stor|
|00001430| 65 64 20 69 6e 20 72 6f | 77 20 6d 61 6a 6f 72 20 |ed in ro|w major |
|00001440| 6f 72 64 65 72 2e 20 59 | 6f 75 20 63 61 6e 20 73 |order. Y|ou can s|
|00001450| 70 65 63 69 66 79 20 74 | 68 65 20 64 69 73 6b 20 |pecify t|he disk |
|00001460| 66 6f 72 0d 0a 6f 70 65 | 6e 69 6e 67 20 74 68 65 |for..ope|ning the|
|00001470| 20 66 69 6c 65 20 6f 6e | 20 74 68 72 6f 75 67 68 | file on| through|
|00001480| 20 74 68 65 20 65 6e 76 | 69 72 6f 6e 6d 65 6e 74 | the env|ironment|
|00001490| 20 76 61 72 69 61 62 6c | 65 0d 0a 54 4d 50 5c 69 | variabl|e..TMP\i|
|000014a0| 6e 64 65 78 7b 59 41 4d | 50 21 54 4d 50 7d 2e 20 |ndex{YAM|P!TMP}. |
|000014b0| 55 73 65 20 74 68 65 20 | 44 4f 53 20 63 6f 6d 6d |Use the |DOS comm|
|000014c0| 61 6e 64 20 5c 76 65 72 | 62 2b 20 53 45 54 20 54 |and \ver|b+ SET T|
|000014d0| 4d 50 3d 44 3a 2b 0d 0a | 62 65 66 6f 72 65 20 72 |MP=D:+..|before r|
|000014e0| 75 6e 6e 69 6e 67 20 79 | 6f 75 72 20 59 41 4d 50 |unning y|our YAMP|
|000014f0| 20 70 72 6f 67 72 61 6d | 2e 20 20 54 68 69 73 20 | program|. This |
|00001500| 77 69 6c 6c 20 74 65 6c | 6c 20 74 68 65 0d 0a 70 |will tel|l the..p|
|00001510| 72 6f 67 72 61 6d 20 74 | 6f 20 75 73 65 20 74 68 |rogram t|o use th|
|00001520| 65 20 44 20 64 72 69 76 | 65 20 66 6f 72 20 74 68 |e D driv|e for th|
|00001530| 65 20 76 69 72 74 75 61 | 6c 20 66 69 6c 65 2e 20 |e virtua|l file. |
|00001540| 54 68 65 0d 0a 63 75 72 | 72 65 6e 74 20 64 69 73 |The..cur|rent dis|
|00001550| 6b 20 69 73 20 75 73 65 | 64 20 69 66 20 79 6f 75 |k is use|d if you|
|00001560| 20 64 6f 20 6e 6f 74 20 | 75 73 65 20 74 68 65 20 | do not |use the |
|00001570| 65 6e 76 69 72 6f 6e 6d | 65 6e 74 0d 0a 76 61 72 |environm|ent..var|
|00001580| 69 61 62 6c 65 2e 20 49 | 66 20 79 6f 75 20 75 73 |iable. I|f you us|
|00001590| 65 20 61 20 52 41 4d 20 | 64 69 73 6b 2c 20 74 68 |e a RAM |disk, th|
|000015a0| 65 6e 20 74 68 65 20 70 | 61 67 69 6e 67 20 73 63 |en the p|aging sc|
|000015b0| 68 65 6d 65 20 69 73 0d | 0a 72 65 61 73 6f 6e 61 |heme is.|.reasona|
|000015c0| 62 6c 79 20 66 61 73 74 | 2e 20 54 68 65 72 65 20 |bly fast|. There |
|000015d0| 69 73 20 61 20 70 65 72 | 66 6f 72 6d 61 6e 63 65 |is a per|formance|
|000015e0| 20 70 65 6e 61 6c 74 79 | 20 66 6f 72 20 75 73 69 | penalty| for usi|
|000015f0| 6e 67 20 61 0d 0a 70 68 | 79 73 69 63 61 6c 20 64 |ng a..ph|ysical d|
|00001600| 69 73 6b 2e 20 4e 6f 74 | 65 20 74 68 61 74 20 74 |isk. Not|e that t|
|00001610| 68 65 20 76 6d 6d 20 66 | 69 6c 65 20 63 61 6e 20 |he vmm f|ile can |
|00001620| 67 72 6f 77 20 61 73 20 | 6c 61 72 67 65 20 61 73 |grow as |large as|
|00001630| 0d 0a 33 32 20 6d 65 67 | 61 62 79 74 65 73 2c 20 |..32 meg|abytes, |
|00001640| 73 6f 20 79 6f 75 72 20 | 64 65 63 69 73 69 6f 6e |so your |decision|
|00001650| 20 74 6f 20 75 73 65 20 | 61 20 52 41 4d 20 64 69 | to use |a RAM di|
|00001660| 73 6b 20 68 69 6e 67 65 | 73 20 6f 6e 0d 0a 74 68 |sk hinge|s on..th|
|00001670| 65 20 73 70 61 63 65 20 | 72 65 71 75 69 72 65 6d |e space |requirem|
|00001680| 65 6e 74 73 20 6f 66 20 | 79 6f 75 72 20 61 70 70 |ents of |your app|
|00001690| 6c 69 63 61 74 69 6f 6e | 2e 20 20 54 68 65 72 65 |lication|. There|
|000016a0| 20 63 61 6e 20 62 65 0d | 0a 61 74 20 6d 6f 73 74 | can be.|.at most|
|000016b0| 20 36 35 35 33 36 20 62 | 6c 6f 63 6b 73 2c 20 65 | 65536 b|locks, e|
|000016c0| 61 63 68 20 61 74 20 35 | 31 32 20 62 79 74 65 73 |ach at 5|12 bytes|
|000016d0| 2c 20 73 6f 20 74 68 65 | 72 65 20 63 61 6e 20 62 |, so the|re can b|
|000016e0| 65 20 61 74 0d 0a 6d 6f | 73 74 20 33 33 2c 35 35 |e at..mo|st 33,55|
|000016f0| 34 2c 34 33 32 20 62 79 | 74 65 73 20 28 6f 72 20 |4,432 by|tes (or |
|00001700| 33 32 2c 37 36 38 20 4b | 62 79 74 65 73 29 20 69 |32,768 K|bytes) i|
|00001710| 6e 0d 0a 5c 24 5c 24 5c | 24 5c 24 76 6d 65 6d 2e |n..\$\$\|$\$vmem.|
|00001720| 74 6d 70 2e 0d 0a 0d 0a | 76 6f 70 65 6e 28 29 5c |tmp.....|vopen()\|
|00001730| 69 6e 64 65 78 7b 76 6d | 6d 21 76 6f 70 65 6e 28 |index{vm|m!vopen(|
|00001740| 29 7d 20 69 73 20 63 61 | 6c 6c 65 64 20 77 68 65 |)} is ca|lled whe|
|00001750| 6e 20 74 68 65 20 66 69 | 72 73 74 20 76 69 72 74 |n the fi|rst virt|
|00001760| 75 61 6c 0d 0a 6d 61 74 | 72 69 78 20 69 73 20 63 |ual..mat|rix is c|
|00001770| 6f 6e 73 74 72 75 63 74 | 65 64 2c 20 73 6f 20 69 |onstruct|ed, so i|
|00001780| 74 20 64 6f 65 73 20 6e | 6f 74 20 6e 65 65 64 20 |t does n|ot need |
|00001790| 74 6f 20 62 65 20 63 61 | 6c 6c 65 64 20 66 6f 72 |to be ca|lled for|
|000017a0| 0d 0a 74 68 65 20 6d 61 | 74 72 69 78 20 61 70 70 |..the ma|trix app|
|000017b0| 6c 69 63 61 74 69 6f 6e | 2e 0d 0a 0d 0a 76 63 6c |lication|.....vcl|
|000017c0| 6f 73 65 28 29 5c 69 6e | 64 65 78 7b 76 6d 6d 21 |ose()\in|dex{vmm!|
|000017d0| 76 63 6c 6f 73 65 28 29 | 7d 20 63 6c 6f 73 65 73 |vclose()|} closes|
|000017e0| 20 74 68 65 20 76 69 72 | 74 75 61 6c 20 6d 65 6d | the vir|tual mem|
|000017f0| 6f 72 79 20 66 69 6c 65 | 20 61 6e 64 0d 0a 73 68 |ory file| and..sh|
|00001800| 75 74 73 20 64 6f 77 6e | 20 74 68 65 20 76 69 72 |uts down| the vir|
|00001810| 74 75 61 6c 20 6d 65 6d | 6f 72 79 20 70 6f 69 6e |tual mem|ory poin|
|00001820| 74 65 72 73 2e 20 54 68 | 69 73 20 66 75 6e 63 74 |ters. Th|is funct|
|00001830| 69 6f 6e 0d 0a 73 68 6f | 75 6c 64 20 62 65 20 63 |ion..sho|uld be c|
|00001840| 61 6c 6c 65 64 20 62 65 | 66 6f 72 65 20 65 78 69 |alled be|fore exi|
|00001850| 74 69 6e 67 20 74 68 65 | 20 70 72 6f 67 72 61 6d |ting the| program|
|00001860| 2e 20 49 66 20 76 63 6c | 6f 73 65 28 29 20 69 73 |. If vcl|ose() is|
|00001870| 0d 0a 6e 6f 74 20 63 61 | 6c 6c 65 64 2c 20 5c 24 |..not ca|lled, \$|
|00001880| 5c 24 5c 24 5c 24 76 6d | 65 6d 2e 74 6d 70 20 69 |\$\$\$vm|em.tmp i|
|00001890| 73 20 6e 6f 74 20 64 65 | 6c 65 74 65 64 20 66 72 |s not de|leted fr|
|000018a0| 6f 6d 20 74 68 65 20 64 | 69 73 6b 2e 0d 0a 0d 0a |om the d|isk.....|
|000018b0| 5c 73 65 63 74 69 6f 6e | 7b 76 6d 61 6c 6c 6f 63 |\section|{vmalloc|
|000018c0| 28 29 20 61 6e 64 20 76 | 66 72 65 65 28 29 7d 0d |() and v|free()}.|
|000018d0| 0a 0d 0a 76 6d 61 6c 6c | 6f 63 28 29 5c 69 6e 64 |...vmall|oc()\ind|
|000018e0| 65 78 7b 76 6d 6d 21 76 | 6d 61 6c 6c 6f 63 28 29 |ex{vmm!v|malloc()|
|000018f0| 7d 20 61 6e 64 20 76 66 | 72 65 65 28 29 5c 69 6e |} and vf|ree()\in|
|00001900| 64 65 78 7b 76 6d 6d 21 | 76 66 72 65 65 28 29 7d |dex{vmm!|vfree()}|
|00001910| 0d 0a 61 6c 6c 6f 63 61 | 74 65 20 61 6e 64 20 66 |..alloca|te and f|
|00001920| 72 65 65 20 6d 65 6d 6f | 72 79 20 66 72 6f 6d 20 |ree memo|ry from |
|00001930| 5c 24 5c 24 5c 24 5c 24 | 76 6d 65 6d 2e 74 6d 70 |\$\$\$\$|vmem.tmp|
|00001940| 2e 20 54 68 65 20 61 6e | 61 6c 6f 67 6f 75 73 0d |. The an|alogous.|
|00001950| 0a 66 75 6e 63 74 69 6f | 6e 73 20 69 6e 20 43 20 |.functio|ns in C |
|00001960| 61 72 65 20 6d 61 6c 6c | 6f 63 28 29 20 61 6e 64 |are mall|oc() and|
|00001970| 20 66 72 65 65 28 29 2e | 20 76 6d 61 6c 6c 6f 63 | free().| vmalloc|
|00001980| 28 29 20 72 65 74 75 72 | 6e 73 20 61 0d 0a 76 6f |() retur|ns a..vo|
|00001990| 69 64 20 68 64 72 2c 20 | 77 68 69 63 68 20 63 61 |id hdr, |which ca|
|000019a0| 6e 20 62 65 20 63 61 73 | 74 2e 20 76 66 72 65 65 |n be cas|t. vfree|
|000019b0| 28 29 20 66 72 65 65 73 | 20 74 68 65 20 6d 65 6d |() frees| the mem|
|000019c0| 6f 72 79 2c 20 62 75 74 | 0d 0a 72 65 74 75 72 6e |ory, but|..return|
|000019d0| 73 20 61 20 31 20 6f 6e | 20 65 72 72 6f 72 20 61 |s a 1 on| error a|
|000019e0| 6e 64 20 73 65 74 73 20 | 61 6e 20 65 72 72 6f 72 |nd sets |an error|
|000019f0| 20 6d 65 73 73 61 67 65 | 20 6e 75 6d 62 65 72 2e | message| number.|
|00001a00| 20 54 68 69 73 0d 0a 64 | 69 66 66 65 72 73 20 66 | This..d|iffers f|
|00001a10| 72 6f 6d 20 66 72 65 65 | 28 29 20 77 68 69 63 68 |rom free|() which|
|00001a20| 20 72 65 74 75 72 6e 73 | 20 6e 6f 20 76 61 6c 75 | returns| no valu|
|00001a30| 65 2e 20 0d 0a 0d 0a 54 | 68 65 20 61 6c 67 6f 72 |e. ....T|he algor|
|00001a40| 69 74 68 6d 73 20 6f 66 | 20 74 68 65 73 65 20 66 |ithms of| these f|
|00001a50| 75 6e 63 74 69 6f 6e 73 | 20 61 72 65 20 64 69 66 |unctions| are dif|
|00001a60| 66 69 63 75 6c 74 20 74 | 6f 20 65 78 70 6c 61 69 |ficult t|o explai|
|00001a70| 6e 2c 0d 0a 73 6f 20 74 | 68 65 20 72 65 61 64 65 |n,..so t|he reade|
|00001a80| 72 20 69 73 20 72 65 66 | 65 72 72 65 64 20 74 6f |r is ref|erred to|
|00001a90| 20 48 6f 6c 75 62 5c 63 | 69 74 65 7b 48 6f 3a 70 | Holub\c|ite{Ho:p|
|00001aa0| 72 7d 20 61 6e 64 0d 0a | 4b 65 72 6e 69 67 68 61 |r} and..|Kernigha|
|00001ab0| 6e 20 61 6e 64 20 52 69 | 74 63 68 69 65 5c 63 69 |n and Ri|tchie\ci|
|00001ac0| 74 65 7b 6b 72 3a 63 70 | 72 67 7d 2e 20 54 6f 6e |te{kr:cp|rg}. Ton|
|00001ad0| 64 6f 20 61 6e 64 0d 0a | 47 69 6d 70 65 6c 5c 63 |do and..|Gimpel\c|
|00001ae0| 69 74 65 7b 74 67 3a 61 | 6e 73 77 7d 20 61 6c 73 |ite{tg:a|nsw} als|
|00001af0| 6f 20 6f 66 66 65 72 20 | 73 6f 6d 65 20 69 6e 73 |o offer |some ins|
|00001b00| 69 67 68 74 20 69 6e 74 | 6f 20 74 68 65 0d 0a 70 |ight int|o the..p|
|00001b10| 72 6f 62 6c 65 6d 2e 20 | 54 68 65 20 62 61 73 69 |roblem. |The basi|
|00001b20| 63 20 69 64 65 61 20 62 | 65 68 69 6e 64 20 76 6d |c idea b|ehind vm|
|00001b30| 61 6c 6c 6f 63 28 29 20 | 69 73 20 74 6f 0d 0a 73 |alloc() |is to..s|
|00001b40| 65 61 72 63 68 20 74 68 | 65 20 66 72 65 65 20 6c |earch th|e free l|
|00001b50| 69 73 74 20 66 6f 72 20 | 61 20 73 65 74 20 6f 66 |ist for |a set of|
|00001b60| 20 62 6c 6f 63 6b 73 20 | 6c 61 72 67 65 20 65 6e | blocks |large en|
|00001b70| 6f 75 67 68 20 74 6f 0d | 0a 66 75 6c 66 69 6c 6c |ough to.|.fulfill|
|00001b80| 20 74 68 65 20 72 65 71 | 75 65 73 74 2e 20 49 66 | the req|uest. If|
|00001b90| 20 6f 6e 65 20 69 73 20 | 6e 6f 74 20 66 6f 75 6e | one is |not foun|
|00001ba0| 64 2c 20 74 68 65 0d 0a | 5c 24 5c 24 5c 24 5c 24 |d, the..|\$\$\$\$|
|00001bb0| 76 6d 65 6d 2e 74 6d 70 | 20 67 72 6f 77 73 2e 20 |vmem.tmp| grows. |
|00001bc0| 54 68 65 20 62 61 73 69 | 63 20 69 64 65 61 20 62 |The basi|c idea b|
|00001bd0| 65 68 69 6e 64 20 76 66 | 72 65 65 28 29 20 69 73 |ehind vf|ree() is|
|00001be0| 20 74 6f 0d 0a 64 65 6c | 65 74 65 20 74 68 65 20 | to..del|ete the |
|00001bf0| 76 6d 65 6d 20 73 74 72 | 75 63 74 75 72 65 20 61 |vmem str|ucture a|
|00001c00| 6e 64 20 70 6c 61 63 65 | 20 74 68 65 20 68 64 72 |nd place| the hdr|
|00001c10| 20 69 6e 20 74 68 65 0d | 0a 66 72 65 65 6c 69 73 | in the.|.freelis|
|00001c20| 74 2e 20 53 70 61 63 65 | 20 61 72 6f 75 6e 64 20 |t. Space| around |
|00001c30| 74 68 65 20 66 72 65 65 | 64 20 62 6c 6f 63 6b 73 |the free|d blocks|
|00001c40| 20 69 73 20 63 6f 61 6c | 65 73 63 65 64 2e 20 54 | is coal|esced. T|
|00001c50| 68 69 73 0d 0a 68 65 6c | 70 73 20 72 65 64 75 63 |his..hel|ps reduc|
|00001c60| 65 20 63 68 65 63 6b 65 | 72 2d 62 6f 61 72 64 69 |e checke|r-boardi|
|00001c70| 6e 67 20 6f 66 20 74 68 | 65 20 6d 65 6d 6f 72 79 |ng of th|e memory|
|00001c80| 2e 20 44 61 74 61 20 69 | 73 20 73 74 6f 72 65 64 |. Data i|s stored|
|00001c90| 0d 0a 69 6e 20 63 6f 6e | 74 69 67 75 6f 75 73 20 |..in con|tiguous |
|00001ca0| 62 6c 6f 63 6b 73 2e 0d | 0a 0d 0a 5c 73 65 63 74 |blocks..|...\sect|
|00001cb0| 69 6f 6e 7b 76 72 65 61 | 64 28 29 20 61 6e 64 20 |ion{vrea|d() and |
|00001cc0| 76 77 72 69 74 65 28 29 | 7d 0d 0a 0d 0a 76 72 65 |vwrite()|}....vre|
|00001cd0| 61 64 28 29 5c 69 6e 64 | 65 78 7b 76 6d 6d 21 76 |ad()\ind|ex{vmm!v|
|00001ce0| 72 65 61 64 28 29 7d 20 | 61 63 63 65 73 73 65 73 |read()} |accesses|
|00001cf0| 20 74 68 65 20 76 69 72 | 74 75 61 6c 20 61 72 72 | the vir|tual arr|
|00001d00| 61 79 0d 0a 65 6c 65 6d | 65 6e 74 2e 20 20 54 68 |ay..elem|ent. Th|
|00001d10| 65 20 70 72 6f 74 6f 74 | 79 70 65 20 69 73 20 76 |e protot|ype is v|
|00001d20| 6f 69 64 20 22 2a 76 72 | 65 61 64 28 68 64 72 20 |oid "*vr|ead(hdr |
|00001d30| 2a 70 2c 20 6c 6f 6e 67 | 20 69 6e 64 65 78 29 22 |*p, long| index)"|
|00001d40| 2e 0d 0a 54 68 65 20 68 | 64 72 20 70 6f 69 6e 74 |...The h|dr point|
|00001d50| 65 72 2c 20 70 2c 20 69 | 73 20 74 68 65 20 76 69 |er, p, i|s the vi|
|00001d60| 72 74 75 61 6c 20 61 72 | 72 61 79 2e 20 54 68 65 |rtual ar|ray. The|
|00001d70| 20 66 75 6e 63 74 69 6f | 6e 20 74 68 75 73 0d 0a | functio|n thus..|
|00001d80| 6d 61 79 20 62 65 20 74 | 68 6f 75 67 68 74 20 6f |may be t|hought o|
|00001d90| 66 20 61 73 20 72 65 61 | 64 69 6e 67 20 70 5b 69 |f as rea|ding p[i|
|00001da0| 6e 64 65 78 5d 2e 20 54 | 68 65 20 62 6c 6f 63 6b |ndex]. T|he block|
|00001db0| 20 6e 75 6d 62 65 72 20 | 66 6f 72 0d 0a 70 5b 69 | number |for..p[i|
|00001dc0| 6e 64 65 78 5d 20 69 73 | 20 63 61 6c 63 75 6c 61 |ndex] is| calcula|
|00001dd0| 74 65 64 2e 20 49 66 20 | 74 68 61 74 20 62 6c 6f |ted. If |that blo|
|00001de0| 63 6b 20 69 73 20 6e 6f | 74 20 69 6e 20 74 68 65 |ck is no|t in the|
|00001df0| 20 62 75 66 66 65 72 2c | 0d 0a 61 6e 64 20 74 68 | buffer,|..and th|
|00001e00| 65 20 62 75 66 66 65 72 | 20 69 73 20 64 69 72 74 |e buffer| is dirt|
|00001e10| 79 2c 20 74 68 65 20 62 | 75 66 66 65 72 20 69 73 |y, the b|uffer is|
|00001e20| 20 77 72 69 74 74 65 6e | 20 62 61 63 6b 20 74 6f | written| back to|
|00001e30| 20 64 69 73 6b 0d 0a 62 | 65 66 6f 72 65 20 74 68 | disk..b|efore th|
|00001e40| 65 20 72 65 71 75 65 73 | 74 65 64 20 62 6c 6f 63 |e reques|ted bloc|
|00001e50| 6b 20 69 73 20 72 65 61 | 64 2e 0d 0a 0d 0a 76 77 |k is rea|d.....vw|
|00001e60| 72 69 74 65 28 29 5c 69 | 6e 64 65 78 7b 76 6d 6d |rite()\i|ndex{vmm|
|00001e70| 21 76 77 72 69 74 65 28 | 29 7d 20 77 72 69 74 65 |!vwrite(|)} write|
|00001e80| 73 20 64 61 74 61 20 6f | 75 74 20 74 6f 0d 0a 5c |s data o|ut to..\|
|00001e90| 24 5c 24 5c 24 5c 24 76 | 6d 65 6d 2e 74 6d 70 20 |$\$\$\$v|mem.tmp |
|00001ea0| 61 74 20 74 68 65 20 69 | 6e 64 69 63 61 74 65 64 |at the i|ndicated|
|00001eb0| 20 68 64 72 20 61 6e 64 | 20 69 6e 64 65 78 2e 20 | hdr and| index. |
|00001ec0| 0d 0a 0d 0a 4e 65 69 74 | 68 65 72 20 6f 66 20 74 |....Neit|her of t|
|00001ed0| 68 65 73 65 20 66 75 6e | 63 74 69 6f 6e 73 20 73 |hese fun|ctions s|
|00001ee0| 68 6f 75 6c 64 20 62 65 | 20 63 61 6c 6c 65 64 20 |hould be| called |
|00001ef0| 69 6e 20 61 20 59 41 4d | 50 0d 0a 70 72 6f 67 72 |in a YAM|P..progr|
|00001f00| 61 6d 20 73 69 6e 63 65 | 20 74 68 65 73 65 20 66 |am since| these f|
|00001f10| 75 6e 63 74 69 6f 6e 73 | 20 61 72 65 20 65 6e 63 |unctions| are enc|
|00001f20| 61 70 73 75 6c 61 74 65 | 64 20 69 6e 20 74 68 65 |apsulate|d in the|
|00001f30| 0d 0a 76 69 72 74 75 61 | 6c 20 76 65 63 74 6f 72 |..virtua|l vector|
|00001f40| 73 20 61 6e 64 20 6d 61 | 74 72 69 63 65 73 2e |s and ma|trices. |
+--------+-------------------------+-------------------------+--------+--------+