[swift-evolution] Evolving UnsafeMutablePointer.alloc (was Re: [Review] SE-0006 Apply API Guidelines to the Standard Library)

Janosch Hildebrand jnosh at jnosh.com
Sun Jan 31 18:48:37 CST 2016

Speaking of memory allocation, another improvement I would like is to allow allocation of **at least** `capacity` elements where the actual capacity of the buffer is part of the return value(s).

Given that dynamic allocators generally work with a fixed set of block sizes (buckets, pages, ...) it seems to make sense to expose this. ManagedBuffer already works this way.

For example you can use `malloc_good_size()` on Darwin to implement this. With the current static function on `UnsafeMutablePointer` you can simply return a tuple with the Pointer and actual capacity but an initializer directly precludes this. OTOH `UnsafeMutableBufferPointer` could support this even more elegantly and a hypothetical future component could probably also easily support this.

- Janosch

More information about the swift-evolution mailing list