3 ms·
I've seen many advocates of C++ claim that RAII [0] is a viable alternative paradigm to garbage collection or even a silver bullet to resource management in gen
by segfaultbuserr 7y ago
I've seen many advocates of C++ claim that RAII [0] is a viable alternative paradigm to garbage collection or even a silver bullet to resource management in general. I find it's useful but I don't believe it's a silver bullet, yet my skill level is not high enough to come up with a counterargument, but you may find this approach interesting.
[0] https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization https://en.wikipedia.org/wiki/Resource_acquisition_is_initia...
- mrkeen 7y agoRAII works as long as you don't have closures, which are prevalent in higher-order/functional settings. If I adhere to RAII, I guarantee that if I allocate something in a scope then it will be de-allocated when I leave the scope. But if I want to return a closure (a function pointer + state) then I can't de-allocate it myself. I thing C++ and Rust are trying to address this kind of thing with move semantics and ownership. Perhaps functional languages will solve this kind of thing with linear types in the future. I'm currently looking into 'defunctionalization', 'lambda lifting', etc. to see if they are viable alternatives.
- thesz 7y agohttps://en.wikipedia.org/wiki/Region-based_memory_management#Region_inference https://en.wikipedia.org/wiki/Region-based_memory_management... You can infer where you should allocate data. It was done 25 years ago. The problem is that for complex programs you end with one big region and this is not useful. Linear types that are visible to the user will not solve these problems. In fact, they will complicate things greatly, because you have to provide two functions for mapping, for example: for normal and linear types. And their mix with normal types is problematic at best. The inference of linear operations in the backend, on the other hand, can be more efficient - you may end up using linear memory references not knowing about that.