> On Jun 11, 2016, at 5:18 AM, Xiaodi Wu via swift-evolution
> wrote:
>
> On Fri, Jun 10, 2016 at 9:55 PM, Jonathan Hull via swift-evolution
> mailto:swift-evolution@swift.org>> wrote:
> I really love this idea. My mental model of it is that it is exactly like
> ‘defer’, except it works on t
> class Foo {
> var ptr: UnsafeMutablePointer {
> deinit {
> ptr.destroy(...)
> ptr.dealloc(...)
> }
> }
>
> init(count: Int = 0, ptr: UnsafeMutablePointer = nil) {
> self.count = count
> self.space = count
>
> self.ptr = UnsafeMutablePointer.alloc(count)
>
I like the idea, I don’t like the potential to capture anything else though, or
for instances to store closure references. It should offer similar performance
to a standard `deinit`.
Instead, what about a sibling to `willSet`, `didSet` etc?
class Foo {
var ptr: UnsafeMutablePointer {
dein
On Fri, Jun 10, 2016 at 9:55 PM, Jonathan Hull via swift-evolution <
swift-evolution@swift.org> wrote:
> I really love this idea. My mental model of it is that it is exactly like
> ‘defer’, except it works on the lifetime of the object instance instead of
> a function/method. Same thing, differe
I really love this idea. My mental model of it is that it is exactly like
‘defer’, except it works on the lifetime of the object instance instead of a
function/method. Same thing, different scope.
I like how the creation and destruction are right next to one another. It also
solves a lot of
Twitter tl;dr:
> Brent: So each instance must remember which init was used for it and then run
> the matching deinit code at deinit time?
> Me: In my version, the constructive act and destructive act are always
> paired, even redundantly, using a stack if needed
> Graham: so all your deferredDei
I really like this idea. Spatially moving cleanup next to unsafe operations is
good practice.
In normal code, I want my cleanup to follow as closely as possible to my unsafe
act:
let buffer: UnsafeMutablePointer =
UnsafeMutablePointer(allocatingCapacity: chunkSize)
defer { buffer.deallocat
Teach init a 'defer'-like ability to deinit
'defer' is a great way to ensure some clean up code is run; it's declaritive
locality to the resource acquisition is a boon to clarity.
Swift offers no support for resources acquired during 'init'.
For an example, from
https://www.mikeash.com/pyblog/