Hacker News new | ask | show | jobs
by zura 4784 days ago
No language with a nondeterministic memory management will ever be able to be an alternative of C++.
2 comments

There isn't anything nondeterministic about garbage collection systems; it is just that it is hard to predict how much time they will take for a call.

However, the same can be said about classical C style memory management. An alloc can be almost immediate or take lots of time because it has to request a fresh memory block from the OS. Similarly, a free can or cannot take time to coalesce blocks.

Yes, the differences are much smaller there, certainly historically, but garbage collectors have improved, and I am not sure that C-style allocators can stay predictable in long-running programs. Let's say you have a terabyte of RAM, and want to run a multi-threaded server in it 'forever'. Chances are that your garbage-collected system will be more stable and use less memory because it can compact memory. A C style allocator would need quite a few heuristics (or maybe, even contain some machine learning code that builds a model of memory allocation patterns) to prevent memory fragmentation. Such features would make their timing less predictable.

Because of that, I think we may at some time see an OS with built-in garbage-collection become mainstream.

> it is just that it is hard to predict how much time they will take for a call.

The problem is not how much but when - you never know when GC fires and interrupts your running code. That is a nondeterminism.

If it interrupts your running code, it only can happen at moments when you allocate memory, just like with malloc. You cannot predict when malloc calls brk(), either.

Also, most OS-es are non-deterministic, anyways. You cannot predict whether your code lives in cache/main memory, or on disk. In some systems, your data even might have to be brought in by a tape robot without your code being aware of it. As soon as a garbage collector manages to get its interruptions to be about equal to delays caused by caching and virtual memory, I doubt many people will care.

I'm not talking about interruptions on allocations, but deallocations.

You never know when GC fires - starts harvesting for memory locations that need to be freed and frees them.

With Gargage collection, there are ni deallocations.

Also, garbage collection does not "harvest for memory locations that need to be freed and frees them.". Garbage collection does not collect garbage, it collects used space.

I think you're misinformed.

Here are some more details if you're interested:

http://en.wikipedia.org/wiki/Garbage_collection_(computer_sc...

Are you sure you know what the language runtime does with your delete or how long a new takes?
I think we already had some conversation about this topic:

https://news.ycombinator.com/item?id=5503066

HN is small ;)

Most likely. :)
Just followed that thread again, and I think we're on the same side :)

I mean, when I say that I prefer deterministic memory management, that includes an automatic reference counting - smart pointers - which are now part of C++11.

On that thread, under my "deterministic", you assumed only "manual" as it seems.

Oh, great! :)