Both structures, Vec<T> and RawVec<T>, allocate memory in the same way: by using the RawVec<T> type. This structure is a wrapper around lower level functions to allocate, reallocate, or deallocate an array in the heap part of the memory, built for use in higher level data structures. Its primary goal is to avoid capacity overflows, out-of-memory errors, and general overflows, which saves the developer a lot of boilerplate code.
The use of this buffer by Vec<T> is straightforward. Whenever the length threatens to exceed capacity, allocate more memory and transfer all elements, shown in the following code:
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve(&mut self, additional: usize) {
self.buf.reserve(self.len, additional);
}
So this goes on to call the reserve() function, followed by the try_reserve(), followed by the amortized_new_size() of RawVec<T>, which also makes the decision about the size:
fn amortized_new_size...