Memory allocation of vector of strings
examples/vectors/memory-strings/src/main.rs
macro_rules! prt { ($var: expr) => { println!( "{:2} {:2} {:p} {:?} {:?}", $var.len(), $var.capacity(), &$var, $var.as_ptr(), $var ); }; } fn main() { let mut animals = vec![String::from("cat"), String::from("dog")]; prt!(animals); prt!(animals[0]); prt!(animals[1]); println!(); animals.extend([String::from("mouse")]); prt!(animals); prt!(animals[0]); prt!(animals[1]); prt!(animals[2]); println!(); animals[0].push_str(" is the most dangerous animal"); prt!(animals); prt!(animals[0]); prt!(animals[1]); prt!(animals[2]); }
2 2 0x7ffeaaaa5a98 0x5e44f7653b80 ["cat", "dog"] 3 3 0x5e44f7653b80 0x5e44f7653bc0 "cat" 3 3 0x5e44f7653b98 0x5e44f7653be0 "dog" 3 4 0x7ffeaaaa5a98 0x5e44f7653c20 ["cat", "dog", "mouse"] 3 3 0x5e44f7653c20 0x5e44f7653bc0 "cat" 3 3 0x5e44f7653c38 0x5e44f7653be0 "dog" 5 5 0x5e44f7653c50 0x5e44f7653c00 "mouse" 3 4 0x7ffeaaaa5a98 0x5e44f7653c20 ["cat is the most dangerous animal", "dog", "mouse"] 32 32 0x5e44f7653c20 0x5e44f7653c90 "cat is the most dangerous animal" 3 3 0x5e44f7653c38 0x5e44f7653be0 "dog" 5 5 0x5e44f7653c50 0x5e44f7653c00 "mouse"
- Each string