6 ms·
No language with a nondeterministic memory management will ever be able to be an alternative of C++.
by zura 13y ago
No language with a nondeterministic memory management will ever be able to be an alternative of C++.
- Someone 13y agoThere 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.
- zura 13y ago> 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.
- Someone 13y agoIf 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.
- zura 13y agoI'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.
- Someone 13y agoWith 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.
- zura 13y agoI think you're misinformed. Here are some more details if you're interested: http://en.wikipedia.org/wiki/Garbage_collection_(computer_science) http://en.wikipedia.org/wiki/Garbage_collection_(computer_sc...
- pjmlp 13y agoAre you sure you know what the language runtime does with your delete or how long a new takes?
- zura 13y agoI think we already had some conversation about this topic: https://news.ycombinator.com/item?id=5503066 https://news.ycombinator.com/item?id=5503066 HN is small ;)
- pjmlp 13y agoMost likely. :)
- zura 13y agoJust 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.
- pjmlp 13y agoOh, great! :)