[swift-evolution] [Review] SE-0006 Apply API Guidelines to the Standard Library

Dave Abrahams dabrahams at apple.com
Sat Jan 23 16:50:56 CST 2016


on Fri Jan 22 2016, Guillaume Lessard <swift-evolution at swift.org> wrote:

> Hello,
>
> I disagree with the following change to UnsafeMutablePointer:
> -  public static func alloc(num: Int) -> UnsafeMutablePointer<Pointee>
> +  public init(allocatingCapacity count: Int)
>
> This would make it the only constructor in any of OpaquePointer,
> UnsafePointer, UnsafeMutablePointer and UnsafeReference to have the
> side-effect of allocating memory. All the others are relatively cheap
> transformations on pointer values, and get used a lot for
> typecasting. An allocating constructor would be less locatable among
> such uses of typecasting-via-constructor. The memory-allocating static
> method has the merit of sticking out, and pairs nicely with the
> necessary deallocation call, like the malloc/free pair.

That's an interesting point; thanks for raising it!

-- 
-Dave



More information about the swift-evolution mailing list