bare::gc
本页内容
API 参考只有英文版,由标准库源代码中的英文文档注释生成。
the collector's controls, and keeping GC objects in place
for raw pointers.
collect_young, set_pause_goal, no_collect, set_heap_limit and
Arena keep pauses out of a frame or a request. A Pinned<T> from
pin keeps the object holding T's data where it is (nabi_gc_pin,
counted) until it is released, where its owner leaves scope.
GcPtr<T> is a managed reference to one T on the GC heap; Weak<T>
refers to a GcPtr<T>'s object without keeping it alive (a WEAK_REF
word).
Structs
GcStatsSource
pub struct GcStatsThe collector's counters since the program started (stats).
Collections of every kind.
Minor collections (the young objects only).
Full collections that stopped the world throughout.
Full collections marked concurrently (two short pauses each).
Time every thread stood stopped, all pauses together, and the longest pause, in nanoseconds.
Bytes of objects alive at the last collection, plus those allocated since.
Bytes the heap holds from the operating system.
Bytes evacuation has moved.
Times an allocating thread helped a concurrent mark instead of stopping the world to finish it.
Bytes
no_collectregions grew the heap by instead of collecting.Collections the heap limit (
set_heap_limit) brought forward.Bytes that may be allocated between two minor collections now (a pause goal changes it).
ArenaSource
pub struct Arena<T>Values for one frame (or one request) in one buffer the collector
neither allocates nor traces object by object: alloc appends a
value in place and reset empties the arena at once, keeping its
memory for the next frame. Copies of an Arena share it.
A value is reached through its ArenaRef, which is plain data (keep
it anywhere, a GC object included). Every reset starts a new
generation, and a reference from an earlier one (or from another
arena) panics when used: it can never read what the next frame put in
its place. The buffer is an ordinary GC object, so what the values
reference stays alive while they are in the arena.
An empty arena.
An empty arena with room for
nvalues before its buffer grows.Append
value; its reference.The value
rnames.The value
rnames,noneonce the arena was reset since (or for another arena's reference).Replace the value
rnames.Whether
rnames a value of this arena's current generation.Values allocated since the last
reset.Whether nothing was allocated since the last
reset.Values the buffer holds before it grows.
Empty the arena at once (its buffer stays for the next frame): every
ArenaRefhanded out so far is invalid from now on.Every value since the last
reset, in allocation order, in a new list.
ArenaRefSource
pub struct ArenaRef<T>A value in an Arena, valid until the arena's next reset.
GcPtrSource
pub struct GcPtr<T>A reference to a GC object holding one T. Copies share the
object. The collector traces it from every frame and object that
holds it and updates it when the object moves; a raw Ptr<T> to the
value exists only under a pin (Pinned<GcPtr<T>>::as_value_ptr).
A new object holding
value.The value.
Replace the value; every copy sees it.
Whether
selfandotherare one object (identity, not value).
WeakSource
pub struct Weak<T>A reference to a GcPtr<T>'s object that does not keep it alive:
once a collection finds the object unreachable
except through weak references, it frees it and every Weak to it
reads none from then on. For caches and observers.
A weak reference to
target's object.The object,
noneonce it was collected.
PinnedSource
pub struct Pinned<T>obj's data held in place.
The pinned object.
The list's first element; dangling for an empty list.
as_data_ptras a pointer to the run of elements.The slice's first element; dangling for an empty slice.
as_data_ptras a pointer to the run of elements.The value in the pinned object.
The UTF-8 bytes (no NUL promised).
The bytes as
c_chars; NUL termination is not promised (useffi::CString).
Traits
PinnableSource
pub trait PinnableWhat pin keeps in place for a value: the GC object holding its
data, none when nothing can move (an empty list; a str, which
stays in place while the Pinned holding it is in scope). A pinned
List or StrBuf cannot grow: its buffer would move.
Functions
collectSource
pub fn collect() A full collection now (it may move every unpinned object). It
stops every thread for the whole collection: to keep pauses short,
leave collecting to the runtime, or call collect_young between
frames.
collect_youngSource
pub fn collect_young() A minor collection now: only the objects allocated since the last collection are looked at, so it costs about what survived of them, not the heap. The cheap moment to collect, between two frames or two requests. While a concurrent full mark runs, it does nothing (the mark finishes on its own, without a long pause).
collect_young_withinSource
pub fn collect_young_within(ms: f64) -> bool collect_young if the last minor collections say it takes at most
ms milliseconds (whatever time is left of the frame); whether it
ran. When it would take longer, nothing runs and the next collection
comes when the young budget is spent.
set_pause_goalSource
pub fn set_pause_goal(ms: f64) Ask the collector to keep its pauses near ms milliseconds (0: no
goal, the default). It sizes the young generation so a minor
collection fits the goal (from what the last ones cost), marks every
full collection concurrently and never compacts the heap on its own
(call collect for that). A goal, not a promise: a pause can still
be longer, for example while the heap grows fast.
set_heap_limitSource
pub fn set_heap_limit(bytes: u64) Keep the heap at most bytes (0: no limit, the default). Collections
come sooner as the heap nears it and are full ones once it is
reached. Live data beyond the limit is not an error: the heap then
grows past it a little at a time, collecting fully at each step.
no_collectSource
pub fn no_collect<R>(f: fn() -> R) -> R f(), with allocation never starting a collection meanwhile, on any
thread: for a frame or a request that must not pause. When the young
budget runs out inside, the heap grows instead (GcStats::grown_bytes
counts it) and the collection comes after the region. A concurrent
mark keeps running and finishes after the region. The heap limit
still holds: past it, a region collects. collect and collect_young
inside still collect.
statsSource
pub fn stats() -> GcStats The collector's counters now. Takes the collector's lock for a moment: read it now and then (a metrics export, once per frame), not in a hot loop.
pinSource
pub fn pin<T: Pinnable>(obj: T) -> Pinned<T> Pin obj's data until the returned guard is released, where its
owner leaves scope.