I was hoping that
auto myPairs = make_unique_for_overwrite<pair<uint64_t, void*>[]>(arraySize);
would give me uninitialized memory for my pair
s. I am overwriting those later anyway and the (unnecessary) initialization is currently responsible for 120ms out of 600ms overall runtime for my algorithm.
What is the most idiomatic way to avoid this initialization?
According to cppreference, the default constructor of std::pair
always value-initializes (aka zeroes) its elements.
The solution is to get rid of pair
. You can replace it with a structure with two members.
I know I could still just allocate ... and then
reinterpret_cast
Attempt to reinterpret_cast
such structure to std::pair
would cause undefined behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With