chez-libs

Artifact [97170bc876]
Login

Artifact 97170bc8768406835739a9e9bf3d29f98083002d:

Wiki page [(system heap)] by murphy 2016-06-03 13:20:24.
D 2016-06-03T13:20:24.621
L (system\sheap)
U murphy
W 1640
<h1>Native Heap Management</h1>

<h2>Synopsis</h2>

<code>(import (system heap))</code>

Native memory allocation and deallocation utilities.

<h2>Operations</h2>

<h3>parameter: <code>heap-allocator</code></h3>

A pair of native allocation and deallocation procedures. The allocation procedure should take a size and produce the address of a zeroed block of memory, the deallocation procedure consumes the address of a block previously returned by the allocation procedure.

<h3>procedure: <code>(heap-alloc <i>size</i>)</code></h3>
<h3>procedure: <code>(heap-alloc <i>size</i> <i>wrap</i>)</code></h3>

Allocates the given number of bytes using the current <tt>heap-allocator</tt> and returns two values. Before allocating, <tt>heap-collect</tt> is called to perform cleanup. Interrupts are disabled while <tt>heap-alloc</tt> runs.

If a wrapper procedure is given, the first returned value is the result of applying it to the address of the new memory block, otherwise the address is returned as is.

The second returned value is a release procedure that deallocates the memory block, unless it has already been deallocated. Calling the release procedure more than once has no adverse effects.

The release procedure is also registered with a guardian and executed by <tt>heap-collect</tt> once all references to the constructed wrapper have gone out of scope. If no wrapper was constructed or the wrapper procedure returned some atom, the release procedure itself is guarded.

<h3>procedure: <code>(heap-collect)</code></h3>

Invokes the release procedures for any memory blocks that have gone out of scope.

Z 1674804f6df8d2e5df9e1813c10271fa