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-3088] UnsafeMutableBufferPointer doesn't have an allocating init #45678

Closed
karwa opened this issue Oct 31, 2016 · 6 comments
Closed

[SR-3088] UnsafeMutableBufferPointer doesn't have an allocating init #45678

karwa opened this issue Oct 31, 2016 · 6 comments
Labels
improvement standard library Area: Standard library umbrella

Comments

@karwa
Copy link
Contributor

karwa commented Oct 31, 2016

Previous ID SR-3088
Radar rdar://problem/31236583
Original Reporter @karwa
Type Improvement
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Improvement
Assignee None
Priority Medium

md5: 49bfddea8da991130821d438f3d14f45

Issue Description:

We have:

  • UnsafeMutablePointer<T>.allocate(...), and

  • UnsafeMutableRawBufferPointer.allocate(...)
    but no UnsafeMutableBufferPointer<T>.allocate(...)

The workaround at the moment is to allocate a UMP and create a UMBP which points to it:

let buffer      = UnsafeMutablePointer<T>.allocate(capacity: n)
let bufferPtr = UnsafeMutableBufferPointer<T>(start: buffer, count: n)
@belkadan
Copy link
Contributor

I'm afraid this would have to go through the Swift Evolution Process, unless I missed some prior discussion.

@karwa
Copy link
Contributor Author

karwa commented Nov 1, 2016

@atrick
Copy link
Member

atrick commented Nov 1, 2016

We talked about adding this convenience API but didn't get around to it in Swift 3.

@belkadan
Copy link
Contributor

belkadan commented Nov 1, 2016

Ah, thanks! (And thanks for linking the discussion.)

@atrick
Copy link
Member

atrick commented Jul 13, 2017

Naturally, adding the `allocate` method implies we should have a `deallocate`. I forgot to mention that in this bug originally. It was an oversight.

From Kelvin Ma, swift-evolution, Pitch: Improved Swift pointers:

add a deallocate() instance method to UnsafeMutableBufferPointer Buffer pointers will be able to deallocate their own memory. This method is equivalent to calling the new deallocate() method on baseAddress!, but is provided so that the user does not have to extract the (not-really) optional baseAddress property. This method does not take a size parameter since Swift is currently only able to free entire memory blocks. This avoids misleading users, and leaves the possibility open for us to add a deallocate(count:) method in the future, or perhaps even a reallocate(toCount:) method.

@glessard
Copy link
Contributor

glessard commented Dec 7, 2017

Implemented as part of SE-0184a

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

4 participants