A budgeted pool of fixed-size chunks with a freelist. Purely accounting — see the module docs for how it maps onto real memory.

Constructors

  • Parameters

    • budgetBytes: number

      The pool's total byte budget (rounded down to whole chunks; must fit at least one chunk).

    • chunkBytes: number

      The fixed chunk size in bytes.

    Returns ChunkedPool

Accessors

  • get bytesInUse(): number
  • Returns number

    Physical bytes currently acquired (chunk-rounded).

  • get chunkBytes(): number
  • Returns number

    The fixed chunk size in bytes.

  • get freeChunks(): number
  • Returns number

    Chunks currently free.

  • get totalBytes(): number
  • Returns number

    The pool's total byte capacity (whole chunks).

  • get totalChunks(): number
  • Returns number

    Total chunks in the pool.

Methods

  • Acquire chunks to hold bytes. All-or-nothing: returns undefined (and changes nothing) if the free chunks can't cover the request — the caller's cue to evict and retry.

    Parameters

    • bytes: number

      The byte size to hold (0 is allowed and acquires no chunks).

    Returns undefined | ChunkSpan

    The span, or undefined if it can't fit.

  • The physical (chunk-rounded) cost of a byte size — what an acquire of bytes actually consumes. Use this for any budget accounting layered above the pool so logical charges cover physical use.

    Parameters

    • bytes: number

      The byte size to round.

    Returns number

    The chunk-rounded byte cost.

  • Return a span's chunks to the freelist. The span must not be used (or released) again afterwards.

    Parameters

    Returns void