4 ms·
> I'm just a hobbyist, but "new" and especially "malloc" are not "right way of doing C++" How do you think the std::vector is implemented under the hood ?
by AlexeyBrin 9y ago
> I'm just a hobbyist, but "new" and especially "malloc" are not "right way of doing C++"
How do you think the std::vector is implemented under the hood ?
- pducks32 9y agoI think what he's saying is that using `std::vector` is better than using pointers and `malloc` from the point of view of doing simple things. (Simple is not the right term but can't think of a better word). I mean 80% of times.
- smhenderson 9y agoSure but they are implemented by C++ specialists that work on this code all the time. I'd trust them to use malloc more correctly and bug free than I'd ever trust myself to do. As long as we're not talking embedded here I'd rather rely on work already done by experts than reinvent the wheel, perhaps poorly.
- jononor 9y agoWith that line of argumentation, why not use sbrk() or poke the syscall directly? :) I'd say prefer the safest, highest-level of abstraction that you can get away with. Which would generally mean std::vector over new/malloc.
- AlexeyBrin 9y agoI have no problem with the use of std::vector (in 90% of cases it is all you need), my problem is with the new trend of shunning any use of new/delete or naked pointers in modern C++.
- jononor 9y agoSure, dogma is not very useful. But when people ask "what should I use" saying "well, there are valid cases for everything" (like someone else in the thread basically did) does not help much either.