Uploaded image for project: 'Swift'
  1. Swift
  2. SR-7378

Data.Deallocator.custom should allow for a context argument

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Reopened
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Foundation
    • Labels:
      None

      Description

      The `Data` custom deallocator is currently defined as taking the ptr and the length:

      case custom((UnsafeMutableRawPointer, Int) -> Swift.Void)
      

      This is problematic when using the feature to wrap an existing buffer (presumably the most common use case), for example: NIO.ByteBuffer.readData

      This thing has to do an allocation to capture the reference to the underlying storage. To avoid that, it would be great to have a context pointer in the custom deallocator, like so:

      case customWithContext((UnsafeMutableRawPointer, Int, UnsafeRawPointer) -> Swift.Void)
      

      This way the dealloc closure would be context free, no extra alloc would be necessary.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              helge Helge Heß
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: