7 ms·
As a counterpoint, I've been ubiquitously using coroutines in C++ as the primary concurrent task scheduling mechanism in database engines for around a decade. I
by jandrewrogers 7y ago
As a counterpoint, I've been ubiquitously using coroutines in C++ as the primary concurrent task scheduling mechanism in database engines for around a decade. It has always been dead simple and mostly straightforward, resource leaks were never an issue, though details vary with coroutine implementation.
Since C++11, memory management has been remarkably easy to get right the first time in complex systems. It isn't just RAII, there are many other mechanics that enable resources to be automagically managed optimally from the perspective of the developer. In my experience across millions of lines of code, resources don't leak ever at this level of abstraction (pre-C++11 is a different story).
I am perennially baffled by what other people are doing with modern C++ that resource leaks are chronic problem. I get the impression there are a large number of C++ programmers that don't grok basic resource management in C++11 (it really isn't that hard) and blame the language when resource management issues occur.
- jb1991 7y agoWell, just write a simple C++11 lambda that uses a reference capture, and store that lambda somewhere and watch your app crash when it that lambda runs after the referenced object is gone. Even if you stick with writing no "new" or "delete" in your code, just as good modern C++ encourages, this simple problem will always be there, and it doesn't just affect lambdas, though that's the sneakiest place it often happens. Of course you can avoid these problems very easily, but you have to be bitten by them first to know how easy they are to write.
- deleted 7y ago[deleted]
- otec 7y agoDon't capture by reference, as you're misusing the language.
- Gene_Parmesan 7y agoExcuse this ignorance from C# land, but how does one get by in C++ without ever writing "new"?
- zabzonk 7y agoUse the Standard Library, which safely encapsulates new and delete.
- Gene_Parmesan 7y agoSmart pointers and so on? As I said in another sibling reply, I have experience in almost everything from C# down to C, functional, etc., with the (almost) sole exception of C++, so I'm always curious in understanding that language's idioms. The idea of needing to employ the standard library to avoid using a core feature of the language seems... interesting? I guess.
- detaro 7y agoYou couldn't implement the standard library or libraries providing tools like the standard library without having "new" etc available in the language. And of course C++ hasn't had all of this from the start, some use cases still like or need to avoid using too much of the standard library, ...
- ncmncm 7y agoMost such cases are delusory. That said, anyone who needs more than a couple of std::shared_ptr in a program is probably Doing It Wrong. I rarely find a use for them; prevalence of std::shared_ptr is often called Java Disease. Similarly, for std::unique_ptr in public interfaces. Finally: implementers of the Standard Library are not confined to using only Standard facilities, so in fact they do not actually need op new. In practice, they use it, but always correctly so you don't typically need it at all.
- zabzonk 7y agoMostly using collection classes such as std::string, std::vector, std::map and so on, but also using smart pointers such as std::unique_ptr for lower-level stuff. And of course, the Standard Library is built on those "core features" - it just makes them easier and safer to use.
- stjohnswarts 7y agoI think it's mostly lack of planning and design, and then a layer gets built on that, and then another layer, because no one is brave enough to risk their job on rewriting a mostly working but brittle piece of code.