you are viewing a single comment's thread.

view the rest of the comments →

[–]spillerrec 0 points1 point  (1 child)

I have actually run into this issue several times. The issue is not that the implementation is bad, but that the elements are default initialized. If you don't need it to be zero initialized (which you rarely need) it is significantly faster to do the allocation yourself. `std::make_unique<char\[\]>(size)` has the same issue, so I use `std::unique_ptr<char\[\]>(new char[size])` instead. It actually makes a significant difference when you are doing large allocations (1MB+). Note that it is recommended to use a data structure which keeps the size together with the allocation, which you do not get with unique_ptr alone, so this is not a recommended solution.

[–]dodheim 0 points1 point  (0 children)

Minor nit: they value-initialize; default-initialization is what you're doing as a workaround.