chez-libs

Update of "(system heap)"
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

Artifact ID: 97170bc8768406835739a9e9bf3d29f98083002d
Page Name:(system heap)
Date: 2016-06-03 13:20:24
Original User: murphy
Next 2fffd6679ec55ecabe21b29eb17f89686c64de79
Content

Native Heap Management

Synopsis

(import (system heap))

Native memory allocation and deallocation utilities.

Operations

parameter: heap-allocator

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.

procedure: (heap-alloc size)

procedure: (heap-alloc size wrap)

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

procedure: (heap-collect)

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