802 karma · joined May 28, 2021
Mb something 've changed since post
Same query - what romanian football player won the premier league
update. Even instant returns correct result without problems
I remember only a single breakage of previously compiling code with the time crate because of a change in type inference, but even there the compiler told me to update the lib. And that’s in 6 years of using Rust.
Damn this is a lot of self correcting
Traveling into kernel flushes branch predictor caches, tlb. So it's not free at all.
int main() {
std::vector<int> vec = {1, 2, 3};
vec.reserve(3);
std::cout << "Initial capacity: " << vec.capacity() << std::endl;
std::cout << "Initial data address: " << (void*)vec.data() << std::endl;
int* ptr = vec.data();
std::cout << "Pointer before push_back: " << (void*)ptr << std::endl;
std::cout << "Value via pointer before push_back: " << *ptr << std::endl;
std::cout << "\nPushing back 4...\n" << std::endl;
vec.push_back(4);
std::cout << "New capacity: " << vec.capacity() << std::endl;
std::cout << "New data address: " << (void*)vec.data() << std::endl;
std::cout << "\nAttempting to access data via the old pointer..." << std::endl;
std::cout << "Old pointer value: " << (void*)ptr << std::endl;
int value = *ptr;
std::cout << "Read from dangling pointer (UB): " << value << std::endl;
return 0;
}
./a.out
Initial capacity: 3
Initial data address: 0x517d2b0
Pointer before push_back: 0x517d2b0
Value via pointer before push_back: 1Pushing back 4...
New capacity: 6 New data address: 0x517d6e0
Attempting to access data via the old pointer... Old pointer value: 0x517d2b0 Read from dangling pointer (UB): 20861