4 ms·
They wouldn't, of course! Releasing resources silently (other than the memory of automatic variables) is very un-C-like.
by enriquto 5y ago
They wouldn't, of course! Releasing resources silently (other than the memory of automatic variables) is very un-C-like.
- dataflow 5y ago> RAII is mostly already there >> Releasing resources silently (other than the memory of automatic variables) is very un-C-like The "R" is literally "resource", right? Sounds like instead of RAII you just meant unique_ptr. Though I beg to differ on whether releasing memory automatically is any different from releasing other resources as far as being C-like is concerned!
- bonzini 5y agoIt's not silent, you do declare that you want it released; you just do it before and it applies to all early returns. For example MUTEX_LOCK_GUARD(&lock) for (i = 0; i < n; i++) if (a[i] == x) return i; return -1; Real world example here: https://github.com/qemu/qemu/blob/master/block/iscsi.c#L325 https://github.com/qemu/qemu/blob/master/block/iscsi.c#L325 And the implementation: https://github.com/qemu/qemu/blob/master/include/qemu/lockable.h https://github.com/qemu/qemu/blob/master/include/qemu/lockab... (after inlining, the abstraction is completely zero cost).