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-2468] Add a predefined enum for a deallocator that matches UnsafeMutableRawPointer.allocate in Data(bytesNoCopy:count:deallocator) #4334

Open
swift-ci opened this issue Aug 24, 2016 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-2468
Radar radar://27987799
Original Reporter slizeray (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Improvement, SDKOverlay
Assignee None
Priority Medium

md5: 350bc083a2e707af5a997f7350836230

Issue Description:

At the moment we must define a custom allocator for the following code:

let retPointer = UnsafeMutableRawPointer.allocate(bytes: size, alignedTo: MemoryLayout<UInt8>.alignment)

let d = Data(bytesNoCopy: retPointer, count: size, deallocator: .custom({ (ptr, size) in
ptr.deallocate(bytes: size, alignedTo: 1)
}))

It would be nice to have a predefined enum for a deallocator that matches UnsafeMutableRawPointer.allocate

@swift-ci
Copy link
Contributor Author

Comment by Stéphane Lizeray (JIRA)

@parkera @atrick here is the feature request we have been discussing about by mail in the swift-users mailing list

@atrick
Copy link
Member

atrick commented Aug 24, 2016

Thanks for filing this.

The same predefined deallocator should work with memory allocated from either:

UnsafeMutablePointer<T>.allocate(capacity:)

or

UnsafeMutableRawPointer.allocate(bytes: alignedTo:)

It just needs to store the size and alignment and invoke:

UnsafeMutableRawPointer.deallocate(bytes: alignedTo:)

@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