Skip to content

Using NeKernel: Ref, NonNullRef, and Leak()

Amlal El Mahrouss edited this page Mar 8, 2026 · 1 revision

Ref, NonNullRef, and Leak()

In the NeKernel system, Ref<T> is a minimal value container for holding T instances without overhead, ideal for scheduler hot paths where copies kill perf.

Abstract:

  • Ref: Wraps a T by value (construct from T or *T* via deref). Provides -> and * for access; always truthy if constructed.
  • Ref::Leak() / TryLeak(): Returns inner T& for raw access/chaining (e.g., ref.Leak()->Leak()). No RAII post-leak, caller owns the ref. Use for explicit escapes; assumes valid inner state.

Example:

Ref<USER_PROCESS> proc = FooBar(pid);  // Wraps USER_PROCESS value
USER_PROCESS& raw = proc.Leak();        // Expose for manual use (e.g., Status = kRunning)

NonNullRef<T>: Strict wrapper around Ref<T> rejects nulls at ctor via MUST_PASS.

Clone this wiki locally