2 ms·
What about how reference counting is done in languages like C++ and Rust? I.e. you explicitly make a value reference-counted, usually for large values (an entir
by IshKebab 11y ago
What about how reference counting is done in languages like C++ and Rust? I.e. you explicitly make a value reference-counted, usually for large values (an entire class for example). Small values like ints are copied.
That seems like the best approach to me. Plus you can use RAII which is a far bigger advantage than any minor speed differences.
- pjmlp 11y agoRAII is also possible in GC languages, just done differently. If the language supports macros or trailing closures, you can somehow have similar approaches to RAII handle classes. with-database { // connection is only accessible here } // connection is now closed and gone with-file { // file is only accessible here } // file is now closed with-mutex { // mutex guarded resource is now visible here } // mutex is now released, regardless of possible errors with-native-memory { // able to use an OS memory block } // OS got the memory back