We recently discovery that some code was using new T[1]
systematically (properly matched to delete[]
), and I'm wondering if this is harmless, or there are some downsides in the generated code (in space or time/performance). Of course, this was hidden behind layers of functions and macros, but that's beside the point.
Logically, it appears to me that both are similar, but are they?
Are compilers allowed to turn this code (using a literal 1, not a variable, but via functions layers, that 1
turns into an argument variable 2 or 3 times before reaching the code using thus new T[n]
) into a scalar new T
?
Any other considerations/things to know about the difference between these two?
question from:
https://stackoverflow.com/questions/58165517/scalar-new-t-vs-array-new-t1 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…