4 ms·
I can't say anything about whether this is a good idea in general or not, but if they are going to do it, then why not just combine the allocation with the defe
by liquidify 6y ago
I can't say anything about whether this is a good idea in general or not, but if they are going to do it, then why not just combine the allocation with the defered free into a single syntax ...
'void* x = defer_free_malloc (...);'
- unwind 6y agoI came to say this too, it seemed like an obvious evolution. I find the "randomness" of the defer-statement a bit scary, like there is too much freedom. There's no guarantee that you're deferring the proper code to free the resource, which somehow should be the default. Not at all sure of the proper syntax, but at least tying it together with something like void * const x = DEFER(malloc(...), free); would make sense. In a more high-level language with interfaces, there should be a way to tie together the creation and destruction into a combined type, and just do obj = acquire SomeType(...); And then 'acquire' should take care that the type to the right implements the interface, and automatically add a deferred call to the proper freeing method. Hm. I guess I just invented some kind of garbage collection, bummer.
- deleted 6y ago[deleted]