RingBufferStorage

final class RingBufferStorage

Storage for RingBuffer

  • Capacity of this storage instance, in bytes

    Declaration

    Swift

    let capacity: Int
  • Pointer to our allocated memory

    Declaration

    Swift

    var storagePointer: UnsafeMutableRawPointer!
  • Base address of the storage, as mapped to UInt8

    Declaration

    Swift

    var baseAddress: UnsafeMutablePointer<UInt8>?
  • Create an instance of RingBufferStorage, with a given capacity, using allocator to allocate the memory.

    Note

    capacity is rounded up to the nearest power of 2. To determine the actual capacity of the buffer, check the return value of capacity.

    Declaration

    Swift

    init(capacity: Int)

    Parameters

    capacity

    The capacity of the storage to allocate

  • Deallocate our storage, if it exists, upon deinitialization

    Declaration

    Swift

    deinit
  • Calls a closure with a pointer to the buffer’s contiguous storage.

    The UnsafeBufferPointer passed to the block will begin at the start address and continue for the entire capacity of the storage, even if the elements are nil.

    Seealso

    withUnsafeMutableBufferPointer, UnsafeBufferPointer

    Declaration

    Swift

    func withUnsafeBufferPointer<ContentType, ResultType>(
        _ body: (UnsafeBufferPointer<ContentType>) throws -> ResultType
      ) rethrows -> ResultType

    Parameters

    body

    A closure with an UnsafeBufferPointer parameter that points to the contiguous storage. If body has a return value, it is used as the return value for the withUnsafeBufferPointer(_:) method. The pointer argument is valid only for the duration of the closure’s execution.

    Return Value

    The return value of the body closure parameter, if any.

  • Calls a closure with a pointer to the buffer’s mutable contiguous storage.

    The UnsafeBufferPointer passed to the block will begin at the start address and continue for the entire capacity of the storage, even if the elements are nil.

    Warning

    Do not rely on anything about self (the buffer that is the target of this method) during the execution of the body closure: It may not appear to have its correct value. Instead, use only the UnsafeMutableBufferPointer argument to body.

    Seealso

    withUnsafeBufferPointer, UnsafeMutableBufferPointer, withUnsafeBytes, withUnsafeMutableBytes

    Declaration

    Swift

    func withUnsafeMutableBufferPointer<ContentType, ResultType>(
        _ body: (UnsafeMutableBufferPointer<ContentType>) throws -> ResultType
      ) rethrows -> ResultType

    Parameters

    body

    A closure with an UnsafeMutableBufferPointer parameter that points to the contiguous storage for the buffer. If body has a return value, it is used as the return value for the withUnsafeMutableBufferPointer(_:) method. The pointer argument is valid only for the duration of the closure’s execution.

    Return Value

    The return value of the body closure parameter, if any.

  • Access the bytes in the data.

    Warning

    The byte pointer argument should not be stored and used outside of the lifetime of the call to the closure.

    Declaration

    Swift

    func withUnsafeBytes<ContentType, ResultType>(
        _ body: (UnsafePointer<ContentType>) throws -> ResultType
      ) rethrows -> ResultType
  • Mutate the bytes in the data.

    This function assumes that you are mutating the contents. - warning: The byte pointer argument should not be stored and used outside of the lifetime of the call to the closure.

    Declaration

    Swift

    func withUnsafeMutableBytes<ContentType, ResultType>(
        _ body: (UnsafeMutablePointer<ContentType>) throws -> ResultType
      ) rethrows -> ResultType