chez-libs

Hex Artifact Content
Login

Artifact 97170bc8768406835739a9e9bf3d29f98083002d:

Wiki page [(system heap)] by murphy 2016-06-03 13:20:24.
0000: 44 20 32 30 31 36 2d 30 36 2d 30 33 54 31 33 3a  D 2016-06-03T13:
0010: 32 30 3a 32 34 2e 36 32 31 0a 4c 20 28 73 79 73  20:24.621.L (sys
0020: 74 65 6d 5c 73 68 65 61 70 29 0a 55 20 6d 75 72  tem\sheap).U mur
0030: 70 68 79 0a 57 20 31 36 34 30 0a 3c 68 31 3e 4e  phy.W 1640.<h1>N
0040: 61 74 69 76 65 20 48 65 61 70 20 4d 61 6e 61 67  ative Heap Manag
0050: 65 6d 65 6e 74 3c 2f 68 31 3e 0d 0a 0d 0a 3c 68  ement</h1>....<h
0060: 32 3e 53 79 6e 6f 70 73 69 73 3c 2f 68 32 3e 0d  2>Synopsis</h2>.
0070: 0a 0d 0a 3c 63 6f 64 65 3e 28 69 6d 70 6f 72 74  ...<code>(import
0080: 20 28 73 79 73 74 65 6d 20 68 65 61 70 29 29 3c   (system heap))<
0090: 2f 63 6f 64 65 3e 0d 0a 0d 0a 4e 61 74 69 76 65  /code>....Native
00a0: 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69   memory allocati
00b0: 6f 6e 20 61 6e 64 20 64 65 61 6c 6c 6f 63 61 74  on and deallocat
00c0: 69 6f 6e 20 75 74 69 6c 69 74 69 65 73 2e 0d 0a  ion utilities...
00d0: 0d 0a 3c 68 32 3e 4f 70 65 72 61 74 69 6f 6e 73  ..<h2>Operations
00e0: 3c 2f 68 32 3e 0d 0a 0d 0a 3c 68 33 3e 70 61 72  </h2>....<h3>par
00f0: 61 6d 65 74 65 72 3a 20 3c 63 6f 64 65 3e 68 65  ameter: <code>he
0100: 61 70 2d 61 6c 6c 6f 63 61 74 6f 72 3c 2f 63 6f  ap-allocator</co
0110: 64 65 3e 3c 2f 68 33 3e 0d 0a 0d 0a 41 20 70 61  de></h3>....A pa
0120: 69 72 20 6f 66 20 6e 61 74 69 76 65 20 61 6c 6c  ir of native all
0130: 6f 63 61 74 69 6f 6e 20 61 6e 64 20 64 65 61 6c  ocation and deal
0140: 6c 6f 63 61 74 69 6f 6e 20 70 72 6f 63 65 64 75  location procedu
0150: 72 65 73 2e 20 54 68 65 20 61 6c 6c 6f 63 61 74  res. The allocat
0160: 69 6f 6e 20 70 72 6f 63 65 64 75 72 65 20 73 68  ion procedure sh
0170: 6f 75 6c 64 20 74 61 6b 65 20 61 20 73 69 7a 65  ould take a size
0180: 20 61 6e 64 20 70 72 6f 64 75 63 65 20 74 68 65   and produce the
0190: 20 61 64 64 72 65 73 73 20 6f 66 20 61 20 7a 65   address of a ze
01a0: 72 6f 65 64 20 62 6c 6f 63 6b 20 6f 66 20 6d 65  roed block of me
01b0: 6d 6f 72 79 2c 20 74 68 65 20 64 65 61 6c 6c 6f  mory, the deallo
01c0: 63 61 74 69 6f 6e 20 70 72 6f 63 65 64 75 72 65  cation procedure
01d0: 20 63 6f 6e 73 75 6d 65 73 20 74 68 65 20 61 64   consumes the ad
01e0: 64 72 65 73 73 20 6f 66 20 61 20 62 6c 6f 63 6b  dress of a block
01f0: 20 70 72 65 76 69 6f 75 73 6c 79 20 72 65 74 75   previously retu
0200: 72 6e 65 64 20 62 79 20 74 68 65 20 61 6c 6c 6f  rned by the allo
0210: 63 61 74 69 6f 6e 20 70 72 6f 63 65 64 75 72 65  cation procedure
0220: 2e 0d 0a 0d 0a 3c 68 33 3e 70 72 6f 63 65 64 75  .....<h3>procedu
0230: 72 65 3a 20 3c 63 6f 64 65 3e 28 68 65 61 70 2d  re: <code>(heap-
0240: 61 6c 6c 6f 63 20 3c 69 3e 73 69 7a 65 3c 2f 69  alloc <i>size</i
0250: 3e 29 3c 2f 63 6f 64 65 3e 3c 2f 68 33 3e 0d 0a  >)</code></h3>..
0260: 3c 68 33 3e 70 72 6f 63 65 64 75 72 65 3a 20 3c  <h3>procedure: <
0270: 63 6f 64 65 3e 28 68 65 61 70 2d 61 6c 6c 6f 63  code>(heap-alloc
0280: 20 3c 69 3e 73 69 7a 65 3c 2f 69 3e 20 3c 69 3e   <i>size</i> <i>
0290: 77 72 61 70 3c 2f 69 3e 29 3c 2f 63 6f 64 65 3e  wrap</i>)</code>
02a0: 3c 2f 68 33 3e 0d 0a 0d 0a 41 6c 6c 6f 63 61 74  </h3>....Allocat
02b0: 65 73 20 74 68 65 20 67 69 76 65 6e 20 6e 75 6d  es the given num
02c0: 62 65 72 20 6f 66 20 62 79 74 65 73 20 75 73 69  ber of bytes usi
02d0: 6e 67 20 74 68 65 20 63 75 72 72 65 6e 74 20 3c  ng the current <
02e0: 74 74 3e 68 65 61 70 2d 61 6c 6c 6f 63 61 74 6f  tt>heap-allocato
02f0: 72 3c 2f 74 74 3e 20 61 6e 64 20 72 65 74 75 72  r</tt> and retur
0300: 6e 73 20 74 77 6f 20 76 61 6c 75 65 73 2e 20 42  ns two values. B
0310: 65 66 6f 72 65 20 61 6c 6c 6f 63 61 74 69 6e 67  efore allocating
0320: 2c 20 3c 74 74 3e 68 65 61 70 2d 63 6f 6c 6c 65  , <tt>heap-colle
0330: 63 74 3c 2f 74 74 3e 20 69 73 20 63 61 6c 6c 65  ct</tt> is calle
0340: 64 20 74 6f 20 70 65 72 66 6f 72 6d 20 63 6c 65  d to perform cle
0350: 61 6e 75 70 2e 20 49 6e 74 65 72 72 75 70 74 73  anup. Interrupts
0360: 20 61 72 65 20 64 69 73 61 62 6c 65 64 20 77 68   are disabled wh
0370: 69 6c 65 20 3c 74 74 3e 68 65 61 70 2d 61 6c 6c  ile <tt>heap-all
0380: 6f 63 3c 2f 74 74 3e 20 72 75 6e 73 2e 0d 0a 0d  oc</tt> runs....
0390: 0a 49 66 20 61 20 77 72 61 70 70 65 72 20 70 72  .If a wrapper pr
03a0: 6f 63 65 64 75 72 65 20 69 73 20 67 69 76 65 6e  ocedure is given
03b0: 2c 20 74 68 65 20 66 69 72 73 74 20 72 65 74 75  , the first retu
03c0: 72 6e 65 64 20 76 61 6c 75 65 20 69 73 20 74 68  rned value is th
03d0: 65 20 72 65 73 75 6c 74 20 6f 66 20 61 70 70 6c  e result of appl
03e0: 79 69 6e 67 20 69 74 20 74 6f 20 74 68 65 20 61  ying it to the a
03f0: 64 64 72 65 73 73 20 6f 66 20 74 68 65 20 6e 65  ddress of the ne
0400: 77 20 6d 65 6d 6f 72 79 20 62 6c 6f 63 6b 2c 20  w memory block, 
0410: 6f 74 68 65 72 77 69 73 65 20 74 68 65 20 61 64  otherwise the ad
0420: 64 72 65 73 73 20 69 73 20 72 65 74 75 72 6e 65  dress is returne
0430: 64 20 61 73 20 69 73 2e 0d 0a 0d 0a 54 68 65 20  d as is.....The 
0440: 73 65 63 6f 6e 64 20 72 65 74 75 72 6e 65 64 20  second returned 
0450: 76 61 6c 75 65 20 69 73 20 61 20 72 65 6c 65 61  value is a relea
0460: 73 65 20 70 72 6f 63 65 64 75 72 65 20 74 68 61  se procedure tha
0470: 74 20 64 65 61 6c 6c 6f 63 61 74 65 73 20 74 68  t deallocates th
0480: 65 20 6d 65 6d 6f 72 79 20 62 6c 6f 63 6b 2c 20  e memory block, 
0490: 75 6e 6c 65 73 73 20 69 74 20 68 61 73 20 61 6c  unless it has al
04a0: 72 65 61 64 79 20 62 65 65 6e 20 64 65 61 6c 6c  ready been deall
04b0: 6f 63 61 74 65 64 2e 20 43 61 6c 6c 69 6e 67 20  ocated. Calling 
04c0: 74 68 65 20 72 65 6c 65 61 73 65 20 70 72 6f 63  the release proc
04d0: 65 64 75 72 65 20 6d 6f 72 65 20 74 68 61 6e 20  edure more than 
04e0: 6f 6e 63 65 20 68 61 73 20 6e 6f 20 61 64 76 65  once has no adve
04f0: 72 73 65 20 65 66 66 65 63 74 73 2e 0d 0a 0d 0a  rse effects.....
0500: 54 68 65 20 72 65 6c 65 61 73 65 20 70 72 6f 63  The release proc
0510: 65 64 75 72 65 20 69 73 20 61 6c 73 6f 20 72 65  edure is also re
0520: 67 69 73 74 65 72 65 64 20 77 69 74 68 20 61 20  gistered with a 
0530: 67 75 61 72 64 69 61 6e 20 61 6e 64 20 65 78 65  guardian and exe
0540: 63 75 74 65 64 20 62 79 20 3c 74 74 3e 68 65 61  cuted by <tt>hea
0550: 70 2d 63 6f 6c 6c 65 63 74 3c 2f 74 74 3e 20 6f  p-collect</tt> o
0560: 6e 63 65 20 61 6c 6c 20 72 65 66 65 72 65 6e 63  nce all referenc
0570: 65 73 20 74 6f 20 74 68 65 20 63 6f 6e 73 74 72  es to the constr
0580: 75 63 74 65 64 20 77 72 61 70 70 65 72 20 68 61  ucted wrapper ha
0590: 76 65 20 67 6f 6e 65 20 6f 75 74 20 6f 66 20 73  ve gone out of s
05a0: 63 6f 70 65 2e 20 49 66 20 6e 6f 20 77 72 61 70  cope. If no wrap
05b0: 70 65 72 20 77 61 73 20 63 6f 6e 73 74 72 75 63  per was construc
05c0: 74 65 64 20 6f 72 20 74 68 65 20 77 72 61 70 70  ted or the wrapp
05d0: 65 72 20 70 72 6f 63 65 64 75 72 65 20 72 65 74  er procedure ret
05e0: 75 72 6e 65 64 20 73 6f 6d 65 20 61 74 6f 6d 2c  urned some atom,
05f0: 20 74 68 65 20 72 65 6c 65 61 73 65 20 70 72 6f   the release pro
0600: 63 65 64 75 72 65 20 69 74 73 65 6c 66 20 69 73  cedure itself is
0610: 20 67 75 61 72 64 65 64 2e 0d 0a 0d 0a 3c 68 33   guarded.....<h3
0620: 3e 70 72 6f 63 65 64 75 72 65 3a 20 3c 63 6f 64  >procedure: <cod
0630: 65 3e 28 68 65 61 70 2d 63 6f 6c 6c 65 63 74 29  e>(heap-collect)
0640: 3c 2f 63 6f 64 65 3e 3c 2f 68 33 3e 0d 0a 0d 0a  </code></h3>....
0650: 49 6e 76 6f 6b 65 73 20 74 68 65 20 72 65 6c 65  Invokes the rele
0660: 61 73 65 20 70 72 6f 63 65 64 75 72 65 73 20 66  ase procedures f
0670: 6f 72 20 61 6e 79 20 6d 65 6d 6f 72 79 20 62 6c  or any memory bl
0680: 6f 63 6b 73 20 74 68 61 74 20 68 61 76 65 20 67  ocks that have g
0690: 6f 6e 65 20 6f 75 74 20 6f 66 20 73 63 6f 70 65  one out of scope
06a0: 2e 0d 0a 0a 5a 20 31 36 37 34 38 30 34 66 36 64  ....Z 1674804f6d
06b0: 66 38 64 32 65 35 64 66 39 65 31 38 31 33 63 31  f8d2e5df9e1813c1
06c0: 30 32 37 31 66 61 0a                             0271fa.