1. object-evict
    1. Introduction
    2. Requirements
    3. Usage
    4. Programming interface
      1. object-evict
      2. object-evict-to-location
      3. object-evicted?
      4. object-release
      5. object-unevict
      6. object-size
    5. Author
    6. Repository
    7. License
    8. Version History

object-evict

Introduction

This extension allows to copy arbitrary Scheme data into unmanaged memory, not subject to garbage collection (called /eviction/). This may be useful for "pinning" down data to be used by foreign code.

Note that the evicted data needs to be released manually.

Requirements

srfi-69

Usage

(import object-evict)

Programming interface

object-evict

[procedure] (object-evict X [ALLOCATOR])

Copies the object X recursively into the memory pointed to by the foreign pointer object returned by ALLOCATOR. The freshly copied object is returned. ALLOCATOR should be a procedure of a single argument (the number of bytes to allocate), and defaults to allocate.

This facility allows moving arbitrary objects into static memory, but care should be taken when mutating evicted data: setting slots in evicted vector-like objects to non-evicted data is not allowed. It is possible to set characters/bytes in evicted strings or byte-vectors, though. It is advisable not to evict ports, because they might be mutated by certain file-operations. object-evict is able to handle circular and shared structures.

Evicted symbols are no longer unique: a fresh copy of the symbol is created, so

(define x 'foo)
(define y (object-evict 'foo))
y                              ==> foo
(eq? x y)                      ==> #f
(define z (object-evict '(bar bar)))
(eq? (car z) (cadr z))         ==> #t

This loss of uniqueness also implies that an evicted structure -- such as one created with define-record -- cannot be operated on with the existing predicate or accessors, as internally a symbol is used to denote the type:

(define-record point x y)
(point? (make-point x y))                  ; => #t
(point? (object-evict (make-point x y)))   ; => #f

object-evict-to-location

[procedure] (object-evict-to-location X POINTER* [LIMIT])

As object-evict but moves the object at the address pointed to by the pointer-like object POINTER*. If the number of copied bytes exceeds the optional LIMIT then an error is signalled (specifically a composite condition of types exn and evict. The latter provides a limit property which holds the exceeded limit. Two values are returned: the evicted object and a new pointer pointing to the first free address after the evicted object.

Use of anything other than a pointer object as the POINTER* argument is questionable.

object-evicted?

[procedure] (object-evicted? X)

Returns #t if X is a non-immediate evicted data object, or #f otherwise.

object-release

[procedure] (object-release X [RELEASER])

Frees memory occupied by the evicted object X recursively. RELEASER should be a procedure of a single argument (a foreign pointer object to the static memory to be freed) and defaults to free.

object-unevict

[procedure] (object-unevict X [FULL])

Copies the object X and nested objects back into the normal Scheme heap. Symbols are re-interned into the symbol table. Strings and byte-vectors are not copied, unless FULL is given and not #f.

object-size

[procedure] (object-size X)

Returns the number of bytes that would be needed to evict the data object X. If X is an immediate object, zero is returned.

Author

The CHICKEN Team

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/object-evict

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

License

Copyright (c) 2014, The CHICKEN Team
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 

Version History

1.0.1
Fix segfault when calling object-evict-to-location with non-fixnum as limit argument (fixes #1631)
1.0
Extracted from lolevel core library unit and released as an egg.