- "Modern C++ Won't Save Us" by alex_gaynor - 14 Updates
Ian Collins <ian-news@hotmail.com>: May 04 07:50AM +1200 On 04/05/2019 01:04, Scott Lurndal wrote: >> I guess that makes you unique.. > There's a large amount of perfectly functional C++ code in the wild > that doesn't use smart pointers or iterators. Unique in "The problem of memory leak and misuse are none issue to me." Code that doesn't use iterators is probably code that doesn't use the standard containers. Such code is either very old, or written for memory constrained systems, possibly without dynamic allocation. I've contributed to both :) -- Ian. |
Ian Collins <ian-news@hotmail.com>: May 04 07:53AM +1200 On 04/05/2019 07:46, Jorgen Grahn wrote: > YMMV, but I put my objects in containers, as part of other objects, or > as locals in functions. Code with is sprinkled with smart pointers > makes me suspicious -- IMO they should be used rarely. The code base I'm currently working in uses them a lot simply because it is event driven and passes shared messages between threads. -- Ian. |
Melzzzzz <Melzzzzz@zzzzz.com>: May 03 07:59PM > YMMV, but I put my objects in containers, as part of other objects, or > as locals in functions. Code with is sprinkled with smart pointers > makes me suspicious -- IMO they should be used rarely. So you put objects by value everywhere? -- press any key to continue or any other to quit... U ničemu ja ne uživam kao u svom statusu INVALIDA -- Zli Zec Na divljem zapadu i nije bilo tako puno nasilja, upravo zato jer su svi bili naoruzani. -- Mladen Gogala |
scott@slp53.sl.home (Scott Lurndal): May 03 08:01PM >>> While you are certainly entitled to your opinion, it's not universally >>> shared. >> How do you solve leaks without sart pointers? Disciplined programming, of course. One writes the code such that leaks cannot occur. You all seem to assume that C++ programmers are all stupid and incapable of writing correct code without using the crutches that have been added to the language over the last two decades. That's obviously not true. Granted, one needs to hire capable programmers, but that's not been a problem, just requires due diligence. |
Melzzzzz <Melzzzzz@zzzzz.com>: May 03 08:13PM >>> How do you solve leaks without sart pointers? > Disciplined programming, of course. One writes the code such that > leaks cannot occur. That depends on code. Smart pointers do what you have to do in all your objects having pointers. You all seem to assume that C++ > two decades. That's obviously not true. Granted, one needs to hire > capable programmers, but that's not been a problem, just requires due > diligence. Smart pointers are not crutches, rather code reuse. If you like to write smart pointer in every class, please do. -- press any key to continue or any other to quit... U ničemu ja ne uživam kao u svom statusu INVALIDA -- Zli Zec Na divljem zapadu i nije bilo tako puno nasilja, upravo zato jer su svi bili naoruzani. -- Mladen Gogala |
Thiago Adams <thiago.adams@gmail.com>: May 03 01:19PM -0700 On Friday, May 3, 2019 at 4:53:40 PM UTC-3, Ian Collins wrote: ... > The code base I'm currently working in uses them a lot simply because it > is event driven and passes shared messages between threads. Can you move the message? Or do you have to share it? |
Thiago Adams <thiago.adams@gmail.com>: May 03 01:22PM -0700 On Friday, May 3, 2019 at 5:02:06 PM UTC-3, Scott Lurndal wrote: > two decades. That's obviously not true. Granted, one needs to hire > capable programmers, but that's not been a problem, just requires due > diligence. Just add some memory leak detector and you will be disciplined. It is very easy to create one and use in debug. For instance: https://github.com/nothings/stb/blob/master/stb_leakcheck.h |
Ian Collins <ian-news@hotmail.com>: May 04 08:31AM +1200 On 04/05/2019 08:19, Thiago Adams wrote: >> The code base I'm currently working in uses them a lot simply because it >> is event driven and passes shared messages between threads. > Can you move the message? Or do you have to share it? They are shared between multiple consumers. -- Ian. |
Ian Collins <ian-news@hotmail.com>: May 04 08:35AM +1200 On 04/05/2019 08:01, Scott Lurndal wrote: > two decades. That's obviously not true. Granted, one needs to hire > capable programmers, but that's not been a problem, just requires due > diligence. "Crutches" such a smart pointers have been a feature of C++ since the beginning because RAII has been a feature of C++ since the beginning. RAII is one of C++'s core design features and greatest strengths. -- Ian |
Ian Collins <ian-news@hotmail.com>: May 04 08:40AM +1200 On 04/05/2019 08:22, Thiago Adams wrote: >> diligence. > Just add some memory leak detector and you will be disciplined. > It is very easy to create one and use in debug. Why drive the ambulance to the bottom of the cliff when it belongs at the top? Besides, memory isn't the only resource that can and should be manages automatically. Opposition to smart pointers (and by inference, RAII in general) is pure Luddism! -- Ian. |
Vir Campestris <vir.campestris@invalid.invalid>: May 03 09:52PM +0100 On 03/05/2019 08:59, Öö Tiib wrote: > Myth. In actual practice Java (and C# that is kind of "better" Java > from Microsoft) programs leak every precious resource there > is: sockets, file descriptors, threads, mutexes and memory. <snip> I chose my words carefully. It is harder to leak resources. It is not impossible. I have an Android based satnav that has to be rebooted every couple of weeks... Andy |
Vir Campestris <vir.campestris@invalid.invalid>: May 03 09:59PM +0100 On 03/05/2019 21:01, Scott Lurndal wrote: > two decades. That's obviously not true. Granted, one needs to hire > capable programmers, but that's not been a problem, just requires due > diligence. I use smart pointers because they make my life easier. When writing Linux Kernel stuff I follow their rules - declare all pointers at the beginning of the function and null them; have a single exit point that release all non-null resources. And in case of error use goto to get there. It works. But it's clumsy, and occupies my mind with useless crud. In C++ when I want a resource I create a variable to hold it when I want it. And make sure it is one that will clean it up for me, so I don't have to worry about whether that list at the end of the function is complete. I can even abort processing mid-function and just return E_FAIL if I want. Andy |
scott@slp53.sl.home (Scott Lurndal): May 03 10:36PM >"Crutches" such a smart pointers have been a feature of C++ since the >beginning because RAII has been a feature of C++ since the beginning. >RAII is one of C++'s core design features and greatest strengths. I beg your pardon. I wasn't aware that smart pointers were part of C++ back in 1989 when we used a language called C++ to write an operating system for a massively parallel processing system called OPUS. Surely you don't need smart pointers to implement RAII; we had a rather clever (at the time) use in that Operating System of a struct with a destructor that was used to track resource allocation during processing of a 'fork' system call - if we needed to bail from the fork prematurely (due to resource unavailability or permissions issues) simply returning from the fork function caused the destructor to run which cleaned up the partially allocated new process as it automatically ran the destructor for the local stack instance of the cleanup class. Even then, allocate in constructor, deallocate in destructor works just fine without smart pointers. |
woodbrian77@gmail.com: May 03 04:06PM -0700 On Friday, May 3, 2019 at 2:47:02 PM UTC-5, Jorgen Grahn wrote: > YMMV, but I put my objects in containers, as part of other objects, or > as locals in functions. Code with is sprinkled with smart pointers > makes me suspicious -- IMO they should be used rarely. Yeah, I'm not as high on smart pointers as I once was. Brian Ebenezer Enterprises - If you can't join 'em, beat 'em. https://github.com/Ebenezer-group/onwards |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment