Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
But use it only if you really can't figure out how much memory you actually need, and even then don't use it in time critical code parts.
CptFox14239dDisagree: look for shared_ptr and weak_ptr, and say goodbye to memory leaks and segfaults.
The coolest part of modern C++ is having regular expressions in the standard. I've waited two decades for it to happen!
Why are people so obsessed with vector?
If you really need continuous memory for the access speed, use array.
If you just need a comfortable container, use list.
There aren't that many reasons to use vector...
... And hash containers are much cooler! 😁
@FrodoSwaggins Depends. The thing that must not happen in time critical parts is putting in another element that triggers malloc behind the scenes. Not only that this can be slow, the runtime even varies a lot. But that's the one feature that discerns std::vector from std::array, not bounds checking.
@Fast-Nop the malloc and memcpy are theoretically amortized constant time, because the scheme is to double the size any time you exceed capacity.
There are also other tricks you can use such as calling .reserve() to realloc the size of the backing buffer manually to something big enough if you know you’re going to need a lot you can do that at startup.
If you absolutely know the size of elements you need, you can use array<> which can do both runtime and static bounds checking depending on whether your fetch is static or runtime.
Your Job Suck?
Take a quick quiz from Triplebyte to skip the job search hassles and jump to final interviews at hot tech firms
Get a Better Job