Uploaded image for project: 'Couchbase .NET client library'
  1. Couchbase .NET client library
  2. NCBC-3261

Where possible use ArrayPool instead of MemoryPool

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Minor
    • 3.3.6
    • None
    • library
    • None
    • 1

    Description

      MemoryPool<T> offers some advantages over ArrayPool<T> (which it uses under the hood) when you need clearly declare who "owns" the item and is responsible for returning it to the pool. This is because you pass around IMemoryOwner<T> (which is IDisposable) which helps to make ownership clear.

      However, it does have performance penalties compared to using the ArrayPool<T>:

      • Allocating the IMemoryOwner<T> on the heap for each rental
      • On older frameworks, it is frequently necessary to use MemoryMarshal to extract the backing array so it may be forwarded to other methods that don't have Span<T> overloads, such as Stream.Write.

      In places where the extra advantages of clear memory ownership don't apply, we should use the ArrayPool<T> instead.

      Attachments

        For Gerrit Dashboard: NCBC-3261
        # Subject Branch Project Status CR V

        Activity

          People

            btburnett3 Brant Burnett
            btburnett3 Brant Burnett
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty