docs

v0.1.2 문서를 보고 있습니다. 이 버전은 더 이상 지원하지 않습니다. 최신 릴리스: v0.1.3 →

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 GcStats

The collector's counters since the program started (stats).

  • pub collections: u64§

    Source

    Collections of every kind.

  • pub minor: u64§

    Source

    Minor collections (the young objects only).

  • pub full: u64§

    Source

    Full collections that stopped the world throughout.

  • pub concurrent: u64§

    Source

    Full collections marked concurrently (two short pauses each).

  • pub pause_total_ns: u64§

    Source

    Time every thread stood stopped, all pauses together, and the longest pause, in nanoseconds.

  • pub pause_max_ns: u64§

    Source
  • pub live_bytes: u64§

    Source

    Bytes of objects alive at the last collection, plus those allocated since.

  • pub heap_bytes: u64§

    Source

    Bytes the heap holds from the operating system.

  • pub moved_bytes: u64§

    Source

    Bytes evacuation has moved.

  • pub assists: u64§

    Source

    Times an allocating thread helped a concurrent mark instead of stopping the world to finish it.

  • pub grown_bytes: u64§

    Source

    Bytes no_collect regions grew the heap by instead of collecting.

  • pub limit_collections: u64§

    Source

    Collections the heap limit (set_heap_limit) brought forward.

  • pub young_budget: u64§

    Source

    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.

  • pub fn new() -> Arena<T>§

    Source

    An empty arena.

  • pub fn with_capacity(n: usize) -> Arena<T>§

    Source

    An empty arena with room for n values before its buffer grows.

  • pub fn alloc(self, value: T) -> ArenaRef<T>§

    Source

    Append value; its reference.

  • pub fn get(self, r: ArenaRef<T>) -> T§

    Source

    The value r names.

  • pub fn try_get(self, r: ArenaRef<T>) -> T | none§

    Source

    The value r names, none once the arena was reset since (or for another arena's reference).

  • pub fn set(self, r: ArenaRef<T>, value: T)§

    Source

    Replace the value r names.

  • pub fn holds(self, r: ArenaRef<T>) -> bool§

    Source

    Whether r names a value of this arena's current generation.

  • pub fn len(self) -> usize§

    Source

    Values allocated since the last reset.

  • pub fn is_empty(self) -> bool§

    Source

    Whether nothing was allocated since the last reset.

  • pub fn capacity(self) -> usize§

    Source

    Values the buffer holds before it grows.

  • pub fn reset(self)§

    Source

    Empty the arena at once (its buffer stays for the next frame): every ArenaRef handed out so far is invalid from now on.

  • pub fn values(self) -> List<T>§

    Source

    Every value since the last reset, in allocation order, in a new list.

Trait implementations 2
  • impl<T> Debug for Arena<T>
  • impl<T> !Sync for Arena<T>

ArenaRefSource

pub struct ArenaRef<T>

A value in an Arena, valid until the arena's next reset.

Trait implementations 3
  • impl<T> Clone for ArenaRef<T>
  • impl<T> Copy for ArenaRef<T>
  • impl<T> Debug for ArenaRef<T>

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).

  • pub const fn new(value: T) -> GcPtr<T>§

    Source

    A new object holding value.

  • pub const fn get(self) -> T§

    Source

    The value.

  • pub const fn set(self, value: T)§

    Source

    Replace the value; every copy sees it.

  • pub const fn same(self, other: GcPtr<T>) -> bool§

    Source

    Whether self and other are one object (identity, not value).

Trait implementations 3

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.

  • pub fn new(target: GcPtr<T>) -> Weak<T>§

    Source

    A weak reference to target's object.

  • pub fn get(self) -> GcPtr<T> | none§

    Source

    The object, none once it was collected.

Trait implementations 3
  • impl<T> Debug for Weak<T>
  • impl<T> !Sync for Weak<T>
  • impl<T> !Send for Weak<T>

PinnedSource

pub struct Pinned<T>

obj's data held in place.

  • pub fn obj(self) -> T§

    Source

    The pinned object.

  • pub fn as_data_ptr(self) -> Ptr<T>§

    Source

    The list's first element; dangling for an empty list.

  • pub fn as_data_many_ptr(self) -> ManyPtr<T>§

    Source

    as_data_ptr as a pointer to the run of elements.

  • pub fn as_data_ptr(self) -> Ptr<T>§

    Source

    The slice's first element; dangling for an empty slice.

  • pub fn as_data_many_ptr(self) -> ManyPtr<T>§

    Source

    as_data_ptr as a pointer to the run of elements.

  • pub fn as_value_ptr(self) -> Ptr<T>§

    Source

    The value in the pinned object.

  • pub fn as_bytes_ptr(self) -> ConstPtr<u8>§

    Source

    The UTF-8 bytes (no NUL promised).

  • pub fn as_c_ptr(self) -> ConstPtr<c_char>§

    Source

    The bytes as c_chars; NUL termination is not promised (use ffi::CString).

Trait implementations 2
  • impl<T> Debug for Pinned<T>
  • impl<T> Drop for Pinned<T>

Traits

PinnableSource

pub trait Pinnable

What 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.