Yes there is; stack vs. heap. You're limited on stack space.You can use the heap (or freestore) without manual memory management, take a look at the RAII idiom.
No disrespect, but there is a point where software projects get so large and complex that it is not possible for any human, no matter how skilled they are to keep the overview over the lifetime of every single object throughout the code. I also thought the same as you when I started out and as soon as I had to work with more than 20000 lines of code I just gave up and started using smart pointers. This is also not a result of bad design or anything of the like. I guess you just haven't reached the break even point yet.
It's only unsafe if you use them incorrectly.
Smart-pointers are just a fad. You can use them safely if you use raw pointers how they were intended to be used, and if you are certain you use new/delete appropriately.
Even in absence of exceptions, there are many adaptions necessary when the objects are deallocated manually. With exceptions, it becomes extremely difficult to handle everything correctly, and once you achieve that, code is completely unreadable.As Nexus had already stated, you just can't make sure that nothing goes wrong in between your 'safe' new and delete calls and thus you have to live in constant fear for memory leaks. With smart pointers/RAII objects the lifetime is well defined, i.e. as soon as the scope is left. No matter what happens between point A and B, if the scope is left the resource will get released.
It's only unsafe if you use them incorrectly.Safety was never a consideration when the concept of pointers came around, as such you can't say that using pointers as intended leads to safety. In C mallocing something and not freeing it is also something that should be avoided (most of the time at least). Before the advent of virtual memory, you didn't even have to allocate and free memory because you had access to the physical bytes yourself. These corner cases show that proper usage isn't a matter of doing the same things all the time. Sometimes you just have to allocate, sometimes you just have to free. This is why safety only became prominent in modern C++ where development cost starts to matter.
Smart-pointers are just a fad. You can use them safely if you use raw pointers how they were intended to be used, and if you are certain you use new/delete appropriately.
There is no need for shared pointers simply because I'm responsible with my pointers.As stated in the other thread, you rarely need shared pointers, unique pointers cover most cases.
Yes - it's for cleanliness of my code as well as control. It's a personal preference; I know exactly where my objects are and when their lifetime begins and ends.You know that also with smart pointers: Lifetime begins at initialization and ends at the end of scope. In contrast to raw pointers, smart pointers guarantee that the objects are actually destroyed, even if you don't explicitely advise them to do so.
Plus, to me it's unreadable using smart pointers. It makes much more sense using raw pointers.Only the declaration may be less readable because you write unique_ptr<T> instead of T*. However, you need much more code for the correct deallocation. As a consequence, in more complex examples, the important tasks of the function tend to get lost between cleanup code.
when dereferencing smart pointers [...] there is indeed overhead.No, smart pointers usually store the pointer directly, and the function call of operator* can be inlined.
What my generally negative disposition to smart pointers is is that they are misused; a lot. [...] A lot of the time they use them without knowing how they really work.This argument applies even more to manual new/delete. Many developers, even experienced ones, make mistakes in memory management. I agree that shared_ptr is heavy and doesn't liberate people of learning how new/delete work. Abuse however is not a general argument against a feature. It happens also in other areas, just take a look at how often inheritance is used incorrectly in C++.
For my own preference, smart pointers are only used when a program-wide or potentially unsafe (throwable) resource is created. However, when using code that never throws, and that doesn't prematurely return (like in your examples) there is absolutely no need to use smart pointers. [...] If I know exactly what is being performed, smart pointers are overkill.Why overkill? Unique pointers don't introduce overhead or more effort. On the contrary, they make code simpler.
But they aren't for free. They still introduce overhead with tracking objects!What do you mean exactly?
While it isn't significant, any smart pointer creates a tracking object; that is, an object (wrapper) to hold the raw pointer itself.
You guys talk a lot but this discussion isn't going anywhere :P
Let's summarize things. Qix is of course wrong (*) but he really likes the way he's doing things, and since he's not a beginner you won't convince him to change his habits.
(*) Smart pointers cause no overhead, thanks to inlining. It's just syntactic sugar and automatic behaviours that you would write anyway, the compiled code is the same. What they do, they do it better than any user code. If you don't think so please send a patch to the development team of your standard C++ library. And if you had a strong argument against them, you would already have provided a use case that demonstrates your point of view.
So please admit that your point of view is purely a personal taste, and let's stop this discussion that could make other people think that smart pointers can be bad. The only thing to say is "use them" -- if you need the features they provide, of course.
I never said they were bad, but instead often used incorrectlyI don't know if it's "often", but yes, they can be used incorrectly, like... anything else.
I don't have to admit anything because I said from the start that not using them is a personal preferenceSo maybe it doesn't deserve such a discussion? If you know the advantages of RAII and smart pointers, but prefer to not use them, what else should be said?
I'm not wrong, just providing another point of view.Sorry for that. I thought you were trying to prove that writing your own code based on raw pointers was better than using the standard smart pointers.
nothing is ever free, laurent; you know thisThe classes we are talking about are free. And we are just waiting for more detailed and stronger arguments from you on this point :P