4 ms·
> Pointers and virtual classes have runtime overhead. If you are sensitive to these overhead, you pretty much already only have C++ as your only choice. Or may
by justicezyx 9y ago
> Pointers and virtual classes have runtime overhead.
If you are sensitive to these overhead, you pretty much already only have C++ as your only choice. Or maybe Rust, but I do not know rust well to comment if Rust does not have such overhead.
> It's not simple to write memory safe code in C++
No, in C++11 or newer, memory safe code is the default. That's the design goal of the newer standards of C++. IMHO, memory safety is no longer a central issue for C++.
> a lot fewer vulnerabilities in C++ codebases.
This only applies to legacy code.
- steveklabnik 9y agoRust doesn't have classes, and therefore doesn't have virtual classes. So it ends up being different. Dynamic dispatch is used pretty rarely in Rust. If you want dynamic dispatch, you don't use a virtual class, you use a "trait object". Basically it's a double pointer: a (pointer to vtable, pointer to data). Technically the C++ standard (as far as I know) doesn't define the exact implementation of this stuff, but in my understanding the vtable pointer is stored with the data. There are pros and cons to each approach.
- justicezyx 9y ago> If you want dynamic dispatch, you don't use a virtual class, you use a "trait object". Is this referring to Rust? Then it sounds like it will have similar overhead as C++'s virtual functions.
- steveklabnik 9y agoYes, it is, and yes, it does. There are small differences due to the stuff I said above, but it's similar.