Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-7378] Data.Deallocator.custom should allow for a context argument #4030

Open
swift-ci opened this issue Apr 8, 2018 · 3 comments
Open

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Apr 8, 2018

Previous ID SR-7378
Radar None
Original Reporter helge (JIRA User)
Type Improvement
Status Reopened
Resolution
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Improvement
Assignee None
Priority Medium

md5: 3e2e0cc975b972d7a9c634e200043281

Issue 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.

@belkadan
Copy link

belkadan commented Apr 9, 2018

The custom deallocator is a closure. It can take any context you want by capturing it.

@belkadan
Copy link

belkadan commented Apr 9, 2018

Oh, I see what you mean. I don't think this is really worth it, but maybe the Foundation folks would disagree.

@belkadan
Copy link

belkadan commented Apr 9, 2018

cc @millenomi, @phausler

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants