This is pretty farfetched, but is the following code \"safe\" (i.e. guaranteed not to cause segmentation fault):
std::vector vec(1); // Ensures th
First note that your memset will truncate the 0x123 to a single byte and write that, not writing a four byte pattern.
Then, don't do that, just use the container: std::vector
However to answer the question it may appear to work specifically for POD types if the compiler doesn't use the allocated space for anything. Certainly if anyone calls resize, insert, push_back etc it'll blow away whatever you've already written into the memory and the size of the vector will be wrong as well. There's just no reason to write such code.