[swift-evolution] [Pitch] Renaming sizeof, sizeofValue, strideof, strideofValue

Erica Sadun erica at ericasadun.com
Thu Jun 2 16:51:11 CDT 2016


> On Jun 2, 2016, at 3:35 PM, Tony Allevato via swift-evolution <swift-evolution at swift.org> wrote:
> 
> On Thu, Jun 2, 2016 at 2:25 PM Xiaodi Wu <xiaodi.wu at gmail.com <mailto:xiaodi.wu at gmail.com>> wrote:
> On the other hand, on its own sizeof() is not unsafe, and so the argument that it should be longer to call attention to itself (by analogy with UnsafePointer) isn't quite apt.
> 
> And I'm not sure we really want to encourage anyone else to be defining a global function named size(of:) anyway, so I wouldn't consider vacating that name for end-user purposes to be a meaningful positive.
> 
> I was thinking more of situations where someone is in a scope (such as a method in a struct or class) that has its own size(of:) method but also needs to do something with the global size(of:) and now has to distinguish the two. I'll admit that the likelihood of all of those stars aligning is probably rare, though.
> 
> That being said, I see no reason to choose a very general name over one that is far more descriptive. We should optimize for the N times an expression is read instead of the one time it's written.

/// Returns the contiguous memory footprint of `T`.
///
/// Does not include any dynamically-allocated or "remote" storage.
/// In particular, `memorySize(ofType: X.self)`, when `X` is a class type, is the
/// same regardless of how many stored properties `X` has.
public func memorySize <T>(ofType: T.Type) -> Int

/// Returns the contiguous memory footprint of  `T`.
///
/// Does not include any dynamically-allocated or "remote" storage.
/// In particular, `memorySize(of: a)`, when `a` is a class instance, is the
/// same regardless of how many stored properties `a` has.
public func memorySize <T>(of: T) -> Int

/// Returns the least possible interval between distinct instances of
/// `T` in memory.  The result is always positive.
public func memoryInterval<T>(ofType: T.Type) -> Int

/// Returns the least possible interval between distinct instances of
/// `T` in memory.  The result is always positive.
public func memoryInterval <T>(of: T) -> Int

/// Returns the minimum memory alignment of `T`.
public func memoryAlignment<T>(ofType: T.Type) -> Int

/// Returns the minimum memory alignment of `T`.
public func memoryAlignment <T>(of: T) -> Int


https://github.com/erica/swift-evolution/blob/sizestride/proposals/XXXX-sidestride.md <https://github.com/erica/swift-evolution/blob/sizestride/proposals/XXXX-sidestride.md>

-- E


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160602/fae9c6d1/attachment.html>


More information about the swift-evolution mailing list