diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2017-02-07 19:08:12 -0500 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2017-02-13 13:41:10 -0500 |
| commit | 22d4adf14aabfb0ea0cfc8daff203e8d474cbc52 (patch) | |
| tree | 47e38ca93da0581bf477919da94d422e469d55ee /src/doc/nomicon/vec-dealloc.md | |
| parent | e943e68a47dfbdd73d34f3b40e628f3031f90b6a (diff) | |
| download | rust-22d4adf14aabfb0ea0cfc8daff203e8d474cbc52.tar.gz rust-22d4adf14aabfb0ea0cfc8daff203e8d474cbc52.zip | |
Port Nomicon to mdbook
1. move everything under a src directory 2. add README.md to the SUMMARY.md
Diffstat (limited to 'src/doc/nomicon/vec-dealloc.md')
| -rw-r--r-- | src/doc/nomicon/vec-dealloc.md | 29 |
1 files changed, 0 insertions, 29 deletions
diff --git a/src/doc/nomicon/vec-dealloc.md b/src/doc/nomicon/vec-dealloc.md deleted file mode 100644 index 706fe680e00..00000000000 --- a/src/doc/nomicon/vec-dealloc.md +++ /dev/null @@ -1,29 +0,0 @@ -% Deallocating - -Next we should implement Drop so that we don't massively leak tons of resources. -The easiest way is to just call `pop` until it yields None, and then deallocate -our buffer. Note that calling `pop` is unneeded if `T: !Drop`. In theory we can -ask Rust if `T` `needs_drop` and omit the calls to `pop`. However in practice -LLVM is *really* good at removing simple side-effect free code like this, so I -wouldn't bother unless you notice it's not being stripped (in this case it is). - -We must not call `heap::deallocate` when `self.cap == 0`, as in this case we -haven't actually allocated any memory. - - -```rust,ignore -impl<T> Drop for Vec<T> { - fn drop(&mut self) { - if self.cap != 0 { - while let Some(_) = self.pop() { } - - let align = mem::align_of::<T>(); - let elem_size = mem::size_of::<T>(); - let num_bytes = elem_size * self.cap; - unsafe { - heap::deallocate(*self.ptr as *mut _, num_bytes, align); - } - } - } -} -``` |
