Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I always wonder about code bases using bolt-on reference counting. I would count C++ shared_ptr and Rust's Arc among them. At this point wouldn't it be better to just use a regular GC language? What I don't like in modern C++ is that almost everything seems to be heap allocated, when it certainly doesn't need to be. In case of GC language you at least get fast allocations and heap compaction. But it is true that resource release is more predictable with RC. On the other hand you get those cascades of releases in RC.

As always it is a game of trade offs, but it is something that bothers me.



> At this point wouldn't it be better to just use a regular GC language?

No, because you wouldn't slap `Arc` on every single variable. The example from the blog post is a dispatcher and `Arc` is then needed for dispatched functions. The same might be true for queues and other stuff where you need to move stuff between threads, but other than that it would be mostly `Arc` free.

As an example: when you write a web service in one of the frameworks like Actix, you typically use `Arc` for stuff that you need to share between all of the handlers like DB connections, queues, counters etc. All of the other stuff would be relatively straightforward Rust without much consideration for lifetimes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: