7 ms·
Thanks, I still prefer exactly-zero ms pauses. Maybe that's just me, but I don't think so. And, I don't think I am giving anything up by skipping them.
by ncmncm 5y ago
Thanks, I still prefer exactly-zero ms pauses. Maybe that's just me, but I don't think so. And, I don't think I am giving anything up by skipping them.
- bloat 5y agoYou don't see any benefits to garbage collection at all? Would you even prefer to do your own memory management if you had a magic GC which never paused? I'd be interested in your reasoning if so.
- ncmncm 5y agoI'm perfectly happy to have all you lot depending on GC. And, I don't "do my own memory management". I just don't rely on a GC to do it.
- taejo 5y agoIt may be constructive to say what you do do, instead of leaving us to guess and telling us we're wrong.
- ncmncm 5y agoI mostly use "}".
- post-it 5y agoYou write programs so short and uncomplex that you rarely need to free memory?
- pwdisswordfish8 5y agoEver heard of RAII?
- maleldil 5y agoThat's still memory management, because you need to worry about lifetimes.
- hiptobecubic 5y agoYou only need to worry that data that you need doesn't go out of scope.
- ncmncm 5y agoIt is automated, not manual, memory management. Just not GC.
- BenjiWiebe 5y agoI interpret it as meaning they don't use dynamic memory allocation.
- ncmncm 5y agoFalse. Use of dynamic memory allocation without GC, without reference-counting (which is GC) and without manual memory management is the usual practice in C++ and Rust. Reference-counting GC is available when it is not too costly, which is common, and more convenient, which is rare. Ordinary automatically-generated destructors handle almost everything, almost all the time. Once in a great while, performance demands a concession such as an arena allocator, which also is not "manual memory management", and also not GC, and is radically cheaper than either one.
- snovv_crash 5y agoMemory isn't the only limited resource which needs to be managed. File handles, network ports, etc. all all need proper design to avoid leaks. If you are used to only the allocation and never the cleanup, your design style won't hand effective management of these other types of resources for which GC isn't an option. I'd use Java if it let me annotate when I want things to be deleted.
- avianlyric 5y agoThis strikes me a somewhat narrow view of the world. Using a GC is an engineering trade-off like any other. Taking a dogmatic view on an engineering trade-off isn't good engineering, and closes you off from exploring other, potentially better, ways of solving the problems you actually care about. (Which probably have nothing to do with the details of memory management) Something tells me you wouldn't say "I prefer exactly no borrow checker [in Rust], and I don't think I'm giving anything up by skipping them".
- ncmncm 5y agoWrong on both counts.
- deleted 5y ago[deleted]
- avianlyric 5y ago> Wrong on both counts. "Tradeoff" implies giving something up, and I just said I hadn't. And, I am happy to abjure the borrow checker; it doesn't solve any problem I have. Either. (Comment was edited while I was writing a response, original comment I responded to above) I'm glad to hear that you've taken the time to understand how GC work, and the trade-offs that languages make when use them. I would be curious to learn more about what you're research as has shown with regards to using a GC in your problem space. It's always interesting to learn about areas of engineering that unique requirements.
- chrisseaton 5y ago> I don't think I am giving anything up by skipping them My understanding is that there are some lock-free algorithms that we do not know how to write without garbage collection [Keir, 2004], so you strictly are giving things up, because you can't use those algorithms. (But I'm not completely up to date on latest lock-free work.)
- ncmncm 5y agoI optimize these days mostly by deleting lock-free apparatus.
- the8472 5y agoIf you don't use a GC then you're either using reference counting or manual memory management. Those have their own costs. With RAII popping stack frames means freeing resources recursively. If your free() implementation takes a lock then that can block other threads too, for an arbitrary time if the object graph being released is large. A garbage collector can do that work concurrently.
- ncmncm 5y agoNot using GC. Not using reference counting. Not using "manual memory management".
- pjmlp 5y agoYeah, right. CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.” https://www.youtube.com/watch?v=JfmTagWcqoE https://www.youtube.com/watch?v=JfmTagWcqoE Better making use of the best practices advised by Herb, otherwise those destructors are going to surprise you.
- jhgb 5y ago> Thanks, I still prefer exactly-zero ms pauses. You're not using caches, then?
- ncmncm 5y agoIf your cache misses are measured in milliseconds, you have a bigger problem than GC pauses.
- pjmlp 5y agoBetter never call the OS memory manager then.
- notacoward 5y agoAlso, avoiding GC pauses while still being subject to interrupts and context switches is a common kind of tunnel vision. Non-GC languages are great for systems programming, but if GC wasn't going to be your biggest source of jitter anyway then using one just means more work and/or more bugs.
- notacoward 5y ago...not using one...
- ncmncm 5y agoThis is why those of us who make low-latency systems turn off interrupts and context switches. Not using a GC does not, in fact, make more work or more bugs, given a language that provides resource management facilities, such as C++ and Rust. Programs using GC do typically leak, and most GCs make leaks much harder to find and fix. Most GCs even make it hard to determine if you have a leak.
- notacoward 5y agoI know you think you're a perfect programmer, but the fact is that most programmers aren't. Of the hundreds, possibly thousands, I've worked with, maybe one in twenty could be counted on to write non-trivial code without introducing new object-lifetime issues that every programmer on that project for ever after would have to keep in mind when interacting with that component. Yes, that includes quite a bit of C++ with RAII etc. but also with threads, callbacks, and ill-fated attempts to avoid copies by using references and move semantics. (C++ RAII is a hack BTW, less a resource management facility than a primitive you can use to build one, always with the sad side effect of forcing programmers to wrap their cleanup code in classes even when it's an ill fit conceptually.) So yes, in practice in real-life teams, manual memory management does lead to more work and more bugs. Only somebody who has never seriously tried to use more than a small fashionable subset of languages could claim otherwise, or that they're not using memory management at all when in fact that's only true for toy programs.
- Skinney 5y agoExactly zero pauses only exist if you never free memory, which for most purposes is not an option. In most languages, freeing all all the heap-allocated objects of a big array will take longer than in a language with GC. The reason pauses tend to be bigger in a GCed language is because all the freeing is being done at once, instead of every single time an object is determined to no longer be needed. In any case, the tradeoff you're making is that you have deal with memory. Even in a language like Rust, you need to care about references, ownership, struct vs heap and possibly even reference counting. You might even be bitten by "running out of memory" due to memory defragmentation. In most cases, you don't need to care about these things in a GC'ed language, at the expense of larger memory usage and possibly noticable pauses.
- nyanpasu64 5y agoI can write (and am in fact developing right now) a music app in a non-GC language, with a real-time audio thread which (unless faced with unusual inputs like hundreds of simultaneous events) performs zero allocations or deallocations after initial startup. It acquires and releases all heap allocations from a wait-free queue between the audio thread and GUI thread. If I were to port the app to C#, I have no way of telling the C# GC to never pause the audio thread, and to only pause the GUI thread. I'm not sure if it's possible for a tracing GC to coexist with a never-paused thread which owns manually memory-managed types, and for the two threads to exchange manually freed or GC'd objects without FFI boilerplate, serialization, or copying. If it exists (and there's a GUI framework written in the GC portion of the language), let me know! Admittedly manual memory management does mean a lot more things to worry about (ranging from manual memory management to lock-free wait-free programming) Personally I find deterministic lifetimes and single ownership which can be moved/swapped to be elegant. However, Qt's QObject system combines the practical disadvantages of manual freeing (having to track complex semantics in your head, and check whether each method call transfers ownership or not, with leaks or use-after-free if you get it wrong) with the inelegance of GC (pervasive aliasing and mutability, unclear ownership, a magical runtime-like system).
- Skinney 5y agoSure, and in your specific use case, the tradeoff of dealing with memory seems worth it. My point was that there are tradeoffs, which you admit. The comment i responded to indicated that there wasn’t one.
- ncmncm 5y ago... and, generally, if you have to insist on falsehoods to make the case for depending on your GC, you haven't, in the end, made a case at all. It is a fact that the majority of programming in modern non-GC languages, such as C++ and Rust, involves no manual memory management, no GC, and no reference counting (which is also GC). The memory-management automation provided by the core language and the standard library are equal to almost all challenges, all by themselves. Thus, users of modern non-GC languages do not experience the pauses seen in GC languages, or the unavoidable pointer chasing, or the cache poisoning, or the "reachable leaks" that are GC languages' dirty secret. They are not, in fact, obliged to "trade off" anything at all for being free of those failings. That is not to say that all design goals are easy to achieve, but overcoming a GC's failings is is not among the activities needed achieve them.
- notacoward 5y ago"Manual memory management" means more than just explicit free(3). If you have to create a destructor, and a class for it to sit in, just to make sure some bit of memory gets freed, that's manual memory management. The falsehoods here are yours.
- ncmncm 5y agoSelf-deception in the terminally confused is always sad to see. It is extremely rare, nowadays, to "create a destructor" to manage memory. The destructors generated automatically from templates in the Standard Library suffice. Creating classes is just programming. So, no, that is not manual memory management.
- notacoward 5y agoYou're confusing implicit with automatic. That's the best illustration of self-deception and "terminally confused" in this thread. If programmers have to think about when something truly goes out of the last scope it'll be in (sometimes not obvious when it's put into and taken out of containers and passed between callbacks) then it's not automatic. If they have to think about whether they can use/pass a reference and be sure it won't outlive the object itself, it's not automatic. These have been issues in every C++ codebase I've seen, so even if I were personally able to create a codebase without those issues it wouldn't change anything. It also doesn't make a difference if you're so accustomed to a certain set of ownership rules that the time you spend thinking about them is very small. It's still not zero, and other programmers who are less inured to the mess still exist. It's OK that these issues exist - as you say it's just programming - but don't delude yourself into thinking that's automatic memory management. It's implicit, but it's not automatic and that means it's (at least partly) manual. When you say you don't use manual memory management but then say you let standard-library templates handle it, that's a contradiction and tantamount to a lie.