28 lines
2.2 KiB
Plaintext
28 lines
2.2 KiB
Plaintext
IN: memory
|
|
USING: help errors ;
|
|
|
|
HELP: begin-scan ( -- )
|
|
{ $description "Moves all objects to tenured space, disables the garbage collector, and resets the heap scan pointer to point at the first object in the heap. The " { $link next-object } " word can then be called to advance the heap scan pointer and return successive objects."
|
|
$nl
|
|
"This word must always be paired with a call to " { $link end-scan } "." }
|
|
{ $notes "This is a low-level facility and can be dangerous. Use the " { $link each-object } " combinator instead." } ;
|
|
|
|
HELP: next-object ( -- obj )
|
|
{ $description "Outputs the object at the heap scan pointer, and then advances the heap scan pointer. If the end of the heap has been reached, outputs " { $link f } ". This is unambiguous since the " { $link f } " object is tagged immediate and not actually stored in the heap." }
|
|
{ $errors "Throws a " { $link heap-scan-error. } " if called outside a " { $link begin-scan } "/" { $link end-scan } " pair." }
|
|
{ $notes "This is a low-level facility and can be dangerous. Use the " { $link each-object } " combinator instead." } ;
|
|
|
|
HELP: end-scan ( -- )
|
|
{ $description "Finishes a heap iteration by re-enabling the garbage collector. This word must always be paired with a call to " { $link begin-scan } "." }
|
|
{ $notes "This is a low-level facility and can be dangerous. Use the " { $link each-object } " combinator instead." } ;
|
|
|
|
HELP: each-object
|
|
{ $values { "quot" "a quotation with stack effect " { $snippet "( obj -- )" } } }
|
|
{ $description "Applies a quotation to each object in the heap. The garbage collector is switched off while this combinator runs, so the given quotation must not allocate too much memory." }
|
|
{ $notes "This word is the low-level facility used to implement the " { $link instances } " and " { $link heap-stats. } " words." } ;
|
|
|
|
HELP: instances
|
|
{ $values { "quot" "a quotation with stack effect " { $snippet "( obj -- ? )" } } { "seq" "a fresh sequence" } }
|
|
{ $description "Outputs a sequence of all objects in the heap which satisfy the quotation." }
|
|
{ $notes "This word relies on " { $link each-object } ", so in particular the garbage collector is switched off while it runs and the given quotation must not allocate too much memory." } ;
|