May 2019
Intermediate to advanced
698 pages
17h 21m
English
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); ...Read now
Unlock full access