[swift-evolution] [Pitch] Renaming sizeof, sizeofValue, strideof, strideofValue
Matthew Johnson
matthew at anandabits.com
Thu Jun 2 20:08:56 CDT 2016
Sent from my iPad
> On Jun 2, 2016, at 4:57 PM, Sean Heber <sean at fifthace.com> wrote:
>
> This might be silly, but what if there were a struct with all of the relevant fields (not sure what the best name would be):
>
> struct MemoryLayout {
> let size: Int
> let alignment: Int
> let stride: Int
> // etc
> }
>
> Then you’d only maybe need two functions:
>
> memoryLayout(of:) and memoryLayout(ofType:)
I like this much better than individual functions. I do not like the next idea that considers using a property. We moved away from that approach with dynamicType and should stick with that direction. It's not worth bringing up that debate again IMO.
>
> Or perhaps just a single property on all types named “memoryLayout” (or whatever) that returns the MemoryLayout struct:
>
> Int.memory.size
> type(of: 42).memoryLayout.size
> // etc
>
> Or just a single property on UnsafePointer if we went that route..
>
> It seems like this sort of approach would keep namespace pollution down, at least?
>
> l8r
> Sean
>
>
>>> On Jun 2, 2016, at 4:55 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>>>
>>> I don't disagree with the points you make. But one can argue that this is a good thing. It calls attention to code that requires extra attention and care. In some ways this is similar to 'UnsafeMutablePointer<T>' vs '*T'. Verbosity was a deliberate choice in that case.
>>
>> You know...rather than introducing a new type like MemoryLayout, would it make sense to do this with static properties on UnsafePointer?
>>
>> UnsafePointer<Int>.pointeeSize
>> UnsafePointer<Int>.pointeeAlignment
>> UnsafePointer<Int>.pointeeSpacing
>>
>> If you need this information, 90% of the time you're probably using UnsafePointer or one of its friends, right?
>>
>> --
>> Brent Royal-Gordon
>> Architechies
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
More information about the swift-evolution
mailing list