Depending on what OP is trying to do; swapping out the internal implementation with array
and then decaying to the old terrible .data()
'pointer that could be anything' when having to cross interfaces and boundaries could be a winner. At least their own stuff gets the benefits of known size, bounds checking and being a real class, and the code improvements can be done a little at a time. I'd almost consider this the main use case for array
- unless for some reason you just absolutely must allocate on the stack, then vector
is better in every way.
Same argument for smart pointers. If some legacy code returns an owning pointer, then get it wrapped up as soon as possible. At least your own code won't leak.
"Essentially at random, and it may change with build flags, compiler version updates, static v. dynamic linking, and who knows what else?" Can't rely on it, I'm afraid. What you can rely on is static init of local variables: