12. SNC (Stack No Checking)¶
SNC is a manually managed pool class that supports a stack-like protocol for allocation and deallocation using allocation frames on allocation points. See Allocation frames.
If mps_ap_frame_pop()
is used on an allocation point in an SNC
pool (after a corresponding call to mps_ap_frame_push()
), then
the objects affected by the pop are assumed to be dead, and are
reclaimed by the collector without checking whether there are any
references to them.
This pool class is intended to be used to implement stack languages like Forth and PostScript, where some objects are allocated in stack frames and are known to be dead when the stack is popped, because the language can ensure that objects that are kept alive when the stack is popped are copied to the heap.
12.1. SNC properties¶
Does not support allocation via
mps_alloc()
.Supports allocation via allocation points only. If an allocation point is created in an SNC pool, the call to
mps_ap_create_k()
accepts one optional keyword argument,MPS_KEY_RANK
.Does not support deallocation via
mps_free()
.Supports allocation frames.
Does not support segregated allocation caches.
Blocks may contain exact references to blocks in the same or other pools (but may not contain ambiguous references or weak references (1), and may not use remote references).
There are no garbage collections in this pool.
Allocations may be variable in size.
The alignment of blocks is configurable.
Blocks do not have dependent objects.
Blocks are not automatically reclaimed.
Blocks are scanned.
Blocks may only be referenced by base pointers.
Blocks are not protected by barriers (1).
Blocks do not move.
Blocks may not be registered for finalization.
Blocks must belong to an object format which provides scan, skip, and padding methods.
Blocks must not have in-band headers.
12.2. SNC interface¶
#include "mpscsnc.h"
-
mps_pool_class_t
mps_class_snc
(void)¶ Return the pool class for an SNC (Stack No Check) pool.
When creating an SNC pool,
mps_pool_create_k()
requires one keyword argument:MPS_KEY_FORMAT
(typemps_fmt_t
) specifies the object format for the objects allocated in the pool. The format must provide a scan method, a skip method, and a padding method.
For example:
MPS_ARGS_BEGIN(args) { MPS_ARGS_ADD(args, MPS_KEY_FORMAT, fmt); res = mps_pool_create_k(&pool, arena, mps_class_snc(), args); } MPS_ARGS_END(args);
When creating an allocation point on an SNC pool,
mps_ap_create_k()
accepts one optional keyword argument:MPS_KEY_RANK
(typemps_rank_t
, defaultmps_rank_exact()
) specifies the rank of references in objects allocated on this allocation point.
For example:
MPS_ARGS_BEGIN(args) { MPS_ARGS_ADD(args, MPS_KEY_RANK, mps_rank_exact()); res = mps_ap_create_k(&ap, awl_pool, args); } MPS_ARGS_END(args);