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-6059] Design an API for raw buffer alignment. #48616

Closed
atrick opened this issue Oct 4, 2017 · 1 comment
Closed

[SR-6059] Design an API for raw buffer alignment. #48616

atrick opened this issue Oct 4, 2017 · 1 comment
Labels
feature A feature request or implementation standard library Area: Standard library umbrella

Comments

@atrick
Copy link
Member

atrick commented Oct 4, 2017

Previous ID SR-6059
Radar rdar://problem/34815495
Original Reporter @atrick
Type New Feature
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels New Feature, LanguageFeatureRequest
Assignee None
Priority Medium

md5: 2969ba87c3e5b85a010514753e681262

Issue Description:

Working with raw buffers is extremely unsafe because all typed loads/store assume alignment, but there's no way to check for and adjust alignment short of retrieving the baseAddress' bitPattern.

Some folks have insisted that specifying the alignment at buffer allocation time mitigates some of the unsafety. I completely disagree. Alignment needs to be ensured at the point that the buffer is used, not when it is allocated.

We should have an API that allows the user to ask for a raw slice of the raw buffer while rounding up to the nearest alignment for T. This API could return a new type, say

RawMemorySlice<T>

which can be used to reinterpret the aligned raw buffer slice as T without binding/rebinding the buffer's memory.

@atrick
Copy link
Member Author

atrick commented Jul 8, 2019

This should be handled when we introduce something like a ReinterpretedPointer<T> type. We should be able to easily ask for an aligned buffer. There's no need for a separate bug for this.

@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
feature A feature request or implementation standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants