1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use OnceLock;
use crate;
use crate;
/// Returns the singleton [`Global`] instance for the garbage collector.
///
/// Use it to configure the collector or read heap statistics. Most programs
/// never need it, since collection runs automatically.
///
/// # Examples
///
/// ```
/// let g = cdpt::global();
/// println!("heap usage: {} bytes", g.estimate_heap_usage());
/// g.enable_collection(false); // pause collection
/// g.enable_collection(true); // resume
/// ```
thread_local!
/// Returns a thread-local [`Handle`] for the garbage collector.
///
/// Each thread gets its own `Handle` automatically. Use it to call
/// [`pin()`](Handle::pin) for access to the managed heap, or pass it to
/// [`Local::protect`](crate::Local::protect) to keep a reference alive after
/// its [`Guard`] is dropped.
///
/// # Examples
///
/// ```
/// let handle = cdpt::handle();
/// let guard = handle.pin();
/// // ... allocate, load, and dereference managed pointers ...
/// drop(guard);
/// ```
/// Shorthand for [`handle().pin()`](Handle::pin).
///
/// Returns a [`Guard`] that lets you allocate, load, and dereference managed
/// pointers. Drop the guard when you are done to let the collector make
/// progress.
///
/// # Examples
///
/// ```
/// let guard = cdpt::pin();
/// // ... access the managed heap ...
/// drop(guard);
/// ```