As you know, we cannot use memset() for zeroing a memory if it is not accessed later because it may be optimized by compiler. I saw a suggestion in cpp ref that we can use std::fill with a volatile pointer to solve this problem. Now here are my questions:
- Does this statement means if the pointer is not
volatile,std::fillmay be optimized too? - How we can get a volatile pointer to a container, for example
vector? Does something like this work?
vector<int> v;
volatile auto ptr = v.data();