<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 7, 2017, at 5:56 PM, Jordan Rose <<a href="mailto:jordan_rose@apple.com" class="">jordan_rose@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Sep 7, 2017, at 17:46, Andrew Trick <<a href="mailto:atrick@apple.com" class="">atrick@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On Sep 7, 2017, at 5:40 PM, Joe Groff <<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>> wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">But then given that, I don't understand why the 'capacity' parameter is necessary. Under what circumstances would it actually be faster than "just" calling malloc_size?<br class=""></blockquote><br class="">The runtime may need to hash the address or traverse a lookup table to find out which allocation pool the block resides in. Now, that’s only if some platform ditches full malloc compatibility for user allocations, so I’m not sure how realistic it is.<br class=""></blockquote><br class="">It seems to me that you could still provide malloc/free compatibility with a zone that had to do a relatively expensive traversal on free() to recover the pool the memory came from; malloc/free just wouldn't be the ideal interface in that situation.<br class=""><br class="">-Joe<br class=""></blockquote><br class="">Joe is right, and I just learned how amazing malloc zones are.<br class=""></div></div></blockquote><br class=""></div><div class=""><div class="">As long as you support multiple allocators (or hide everything behind malloc/free), there's already a cost of malloc_zone_from_ptr or equivalent. Without seeing a concrete use case, I wouldn't want to stay with the harder-to-use API <i class="">in UnsafePointer itself.</i> It might be a feature of a <i class="">particular</i> allocator that you need to keep the capacity around, but it <i class="">isn't</i> something generally true about Swift's memory model, and probably never will be.</div><div class=""><br class=""></div><div class="">(Interesting reference points: malloc/malloc.h and <a href="https://opensource.apple.com/source/libmalloc/libmalloc-116.50.8/src/malloc.c.auto.html" class="">the implementation of malloc on macOS</a> - search for "free(void *ptr)".)</div><div class=""><br class=""></div></div>Jordan</div></div></blockquote><br class=""></div><div>I’m primarily arguing from the point of view that UnsafeBufferPointer should pass it’s deallocation capacity and should be implementable in terms of UnsafePointer. But I’m fine hiding the capacity argument from the public API for now. We know what the proposal author wants to do, so unless Joe still feels strongly, we could accept the proposal as-is, put the API decision to rest and focus on better documentation and and assertions.</div><div><br class=""></div><div>-Andy</div></body></html>