CmpStr - v3.4.0
    Preparing search index...

    Class RingPool<T>

    RingPool is a circular buffer implementation that manages a pool of buffers.

    It allows for efficient acquisition and release of buffers, ensuring that buffers are reused without unnecessary allocations.

    Type Parameters

    • T

      The type of buffers managed by the pool

    Index
    • Creates a new RingPool with a specified maximum size.

      Type Parameters

      • T

        The type of buffers managed by the pool

      Parameters

      • maxSize: number

        The maximum number of buffers that can be stored in the pool

      Returns RingPool<T>

    buffers: PoolBuffer<T>[] = []

    The buffers in the pool

    buffersInUse: Set<number> = ...

    The set of buffer IDs in use

    lastID: number = 0

    Largest buffer ID in the pool

    maxSize: number

    The maximum number of buffers that can be stored in the pool

    pointer: number = 0

    The current pointer for acquiring buffers

    • Acquires a buffer of at least the specified minimum size from the pool.

      Parameters

      • minSize: number

        The minimum size of the buffer to acquire

      • allowOversize: boolean

        Whether to allow buffers larger than minSize

      Returns PoolBuffer<T> | null

      • The acquired buffer or null if no suitable buffer is found
      • Throws an error if the acquisition process fails
    • Clears the pool, removing all buffers. This resets the pointer and empties the buffer list.

      Returns void

    • Releases a buffer back to the pool. If the pool is full, it replaces the oldest buffer with the new one.

      Parameters

      • item: Buffer<T>

        The buffer to release back to the pool

      Returns void

      • Throws an error if the release process fails