[previous] [up] [next]     [contents] [index]
Next: Scheme Namespaces (Top-Level Environments) Up: Memory Allocation Previous: Memory Allocation

Library Functions

void *scheme_malloc(size_t n) 

Allocates n bytes of collectable memory.

void *scheme_malloc_atomic(size_t n) 

Allocates n bytes of collectable memory containing no pointers visible to the garbage collector.

void *scheme_malloc_stubborn(size_t n) 

Allocates n bytes of collectable memory that is intended for use with scheme_end_stubborn_change.

void *scheme_malloc_uncollectable(size_t n) 

Allocates n bytes of uncollectable memory.

void *scheme_malloc_eternal(size_t n) 

Allocates uncollectable atomic memory. This function is equivalent to malloc except that it the memory cannot be freed.

void scheme_end_stubborn_change(void *p) 

Promises that the contents of p will never be changed.

void *scheme_calloc(size_t num, size_t size) 

Allocates num * size bytes of memory.

char *scheme_strdup(char *str) 

Copies the null-terminated string str; the copy is collectable.

char *scheme_strdup_eternal(char *str) 

Copies the null-terminated string str; the copy will never be freed.

void *scheme_malloc_fail_ok(void *(*mallocf)(size_t size), size_t size) 

Attempts to allocate size bytes using mallocf. If the allocation fails, the exn:misc:out-of-memory exception is raised.

void scheme_register_extension_global(void *ptr, long size) 

Registers an extension's global variable that can contain Scheme pointers. The address of the global is given in ptr, and its size in bytes in size. This function can actually be used to register any permanent memory that the collector would otherwise treat as atomic.

void scheme_weak_reference(void **p) 

Registers the pointer *p as a weak pointer; when no other (non-weak) pointers reference the same memory as *p references, then *p will be set to NULL by the garbage collector. The value in *p may change, but the pointer remains weak with respect to the value of *p at the time p was registered.

void scheme_weak_reference_indirect(void **p, void *v) 

Like scheme_weak_reference, but *p is cleared (regardless of its value) when there are no references to v.

void scheme_register_finalizer(void *p, void (*f)(void *p, void *data), void *data, 
     void (**oldf)(void *p, void *data), void **olddata) 

Registers a callback function to be invoked when the memory p would otherwise be garbage-collected. The f argument is the callback function; when it is called, it will be passed the value p and the data pointer data; data can be anything -- it is only passed on to the callback function. If oldf and olddata are not NULL, then *oldf and *olddata are filled with with old callback information (f and data will override ths old callback).

Note: registering a callback not only keeps p from collection until the callback is invoked, but it also keeps data from collection.

void scheme_add_finalizer(void *p, void (*f)(void *p, void *data), void *data) 

Adds a finalizer to a chain of primitive finalizers. This chain is separate from the single finalizer installed with scheme_register_finalizer; all finalizers in the chain are called immediately after a finalizer that is installed with scheme_register_finalizer.

void scheme_add_scheme_finalizer(void *p, void (*f)(void *p, void *data), void *data) 

Installs a ``will''-like finalizer, similar to register-will. Scheme finalizers are called one at a time, requiring the collector to prove that a value has become inaccesibile again before calling the next Scheme finalizer.

void scheme_dont_gc_ptr(void *p) 

Keeps the collectable block p from garbage collection. Use this procedure when a reference to p is be stored somewhere inaccessible to the collector. Once the reference is no longer used from the inaccessible region, de-register the lock with scheme_gc_ptr_ok.

This function keeps a reference count on the pointers it registers, so two calls to scheme_dont_gc_ptr for the same p should be balanced with two calls to scheme_gc_ptr_ok.

void scheme_gc_ptr_ok(void *p) 

See scheme_dont_gc_ptr.

void scheme_collect_garbage() 

Forces an immediate garbage-collection.


[previous] [up] [next]     [contents] [index]
Next: Scheme Namespaces (Top-Level Environments) Up: Memory Allocation Previous: Memory Allocation

PLT