Struct Stack
pub struct Stack { /* private fields */ }Expand description
Represents the currently active stack.
§Stack painting
Stack allows to measure the amount of stack effectively used through a technique called
stack painting:
- When initializing the memory stack, it is filled with a sequence of bytes of known values: the paint.
- This paint gets covered during execution with the values stored on stack.
- When requested, the amount of covered paint is measured to estimate the amount of stack used during execution.
Note that this technique only provides a lower bound of stack usage, as the values stored in the stack may “collide” with the paint values. In the current implementation, and assuming the stack data follows a uniform distribution, this is unlikely to result in an underestimation of more than one byte.
§Note
On native, the stack modeled by this type is currently empty, so its usage and free space will both be reported as zero.
Implementations§
§impl Stack
impl Stack
pub fn get() -> Stack
pub fn get() -> Stack
Returns a handle for the currently active stack.
§Panics
Panics when the world is on fire (e.g., when the limits returned by the architecture-dependent code don’t make sense).
pub fn current_free_space(&self) -> usize
pub fn current_free_space(&self) -> usize
Returns the amount of currently free stack space.
pub fn current_usage(&self) -> usize
pub fn current_usage(&self) -> usize
Returns the amount of currently used stack space.
pub fn peak_usage(&self) -> usize
pub fn peak_usage(&self) -> usize
Returns the peak amount of stack used since last repaint.
This re-calculates and thus runs in O(n)!
pub fn repaint(&self)
pub fn repaint(&self)
Repaints the stack.
§Panics
Only panics if its internal sanity check fails, which would point to a bug.