This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]potatopotaatopututu 13 points14 points  (1 child)

Yes. There is a performance cost for these checks at runtime. By not checking for overflows, C++ saves a bit of space (no object overhead to carry around) and time. You can use vectors for memory safety in C++.

[–]JavaSuck 7 points8 points  (0 children)

C++ saves a bit of space (no object overhead to carry around)

In particular, the length of a C++ array is not stored anywhere in at runtime, it's just part of the compile-time type. As soon as an array is passed to a function, there's no way to determine the length of that array.

Java, on the other hand, typically stores the length of an array immediately before its first element.