boehm_gc 0.0.1

Rust allocator and interface for the Boehm GC

Crate boehm_gc [] [src]

boehm_gc is an allocator crate that provides an interface to the Boehm conservative garbage collector. The allocator that this crate provides ensures that all objects that it allocates will root any GC'd pointers that the objects may contain. GC'd pointers are allocated using the gc_allocate function and are freed automatically as they become unreachable.

This crate can only be used with recent Rust nightlies due to the allocator feature being brand new.

Enums

FinalizerMode

Used as an argument to register_finalizer to influence the circumstances upon which the garbage collector will run finalizers.

Functions

__rust_allocate

This implementation of __rust_allocate invokes GC_malloc_uncollectable, which allocates memory that is not collectable by the garbage collector but is capable of rooting GC'd pointers. Any pointer that resides in memory allocated by Rust's allocator will be traced for pointers, and any pointers that are contained within this memory are considered to be rooted.

__rust_deallocate

Deallocates memory allocated by GC_malloc_uncollectable. This memory isn't normally collectable so we rely on Rust's drop glue to free the memory that it's allocated. Luckily, it's really good at that sort of thing!

__rust_reallocate
__rust_reallocate_inplace
__rust_usable_size
bytes_since_gc

Returns the number of bytes allocated since the last GC.

free_bytes

Returns a lower bound on the number of free bytes in the heap.

gc_allocate

Allocates size bytes on the managed heap and returns a pointer to the newly-allocated memory. This memory is tracked by the garbage collector and will be freed automatically when it is no longer reachable.

gc_collect

Forces the garbage collector to run, deallocating any unreachable memory. This is a full, stop-the-world collection.

gc_disable

Disables the garbage collector and prevents gc_collect() from doing anything.

gc_enable

Enables the garbage collector, if the number of times that gc_enable() has been called is the same as the number of times that gc_disable() has been called.

heap_size

Returns the number of bytes in the managed heap, including empty blocks and fragmentation loss.

register_finalizer

Attaches a finalizer function and metadata object to a garbage-collected pointer. The finalizer function will be run right before an object is collected, after it has become unreachable. The first argument to the finalizer function will be the object being collected (the ptr argument), while the second argument to the finalizer function will be the metadata object passed as the data argument.

set_oom_fn

Sets the function that the GC calls when all available memory is exhausted. For now, this function must not return. The Boehm GC /does/ allow the function to return, but it must return either null or a previously-allocated heap object.

total_bytes

Returns the total number of bytes allocated in this process.