From a7fbd67746f2a46d37e17e6557a0140fa3737372 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Mon, 20 Dec 2021 22:03:37 +0100 Subject: [PATCH] ascii art uwu --- README.md | 36 ++++++++++++++++++------------------ src/lib.rs | 32 ++++++++++++++++---------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 33b10b2..1445e09 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,30 @@ # A `Vec` -It's implemented by laying out the elements in memory contiguously like [`alloc::vec::Vec`] +It's implemented by laying out the elements in memory contiguously like `alloc::vec::Vec` # Layout -A [`Vechonk`] is 3 `usize` long. It owns a single allocation, containing the elements and the metadata. +A `Vechonk` is 3 `usize` long. It owns a single allocation, containing the elements and the metadata. The elements are laid out contiguously from the front, while the metadata is laid out contiguously from the back. Both grow towards the center until they meet and get realloced to separate them again. ```txt Vechonk - ------------------------------------ - | ptr | len | cap | elem_size | - ---|---------------|--------|------- - | | | - | |_______ | ______________________________________ - | | | - | _________| | - Heap v v v - -----------------------|----------------------------------------------- -value | "hello" | "uwu" | | 0 - 5 | 5 - 3 | - |------------|---------|-----------------|--------------|--------------| - size | dynamic | dynamic | rest of alloc | usize + meta | usize + meta | - --------------------------------------------|--------------|------------ - ^ ^ | | - |___________ | _________________________| | - |_________________________________________| + ╭──────────────────────────────────╮ + │ ptr | len | cap | elem_size │ + ╰──────────────────────────────────╯ + │ │ │ + │ ╰────────│──────────────────────────────────────╮ + │ │ │ + │ ╭────────╯ │ + Heap ▼ ▼ ▼ + ╭────────────┬─────────┬─────────────────┬──────────────┬──────────────╮ +value │ "hello" │ "uwu" │ │ 0 - 5 │ 5 - 3 │ + ├────────────┼─────────┼─────────────────┼──────────────┼──────────────┤ + size │ dynamic │ dynamic │ rest of alloc │ usize + meta │ usize + meta │ + ╰────────────┴─────────┴─────────────────┴──────────────┴──────────────╯ + ▲ ▲ │ │ + ╰────────────│──────────────────────────╯ │ + ╰─────────────────────────────────────────╯ ``` \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 5771366..44d9004 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,22 +16,22 @@ //! ```txt //! //! Vechonk -//! ------------------------------------ -//! | ptr | len | cap | elem_size | -//! ---|---------------|--------|------- -//! | | | -//! | |_______ | ______________________________________ -//! | | | -//! | _________| | -//! Heap v v v -//! -----------------------|----------------------------------------------- -//! value | "hello" | "uwu" | | 0 - 5 | 5 - 3 | -//! |------------|---------|-----------------|--------------|--------------| -//! size | dynamic | dynamic | rest of alloc | usize + meta | usize + meta | -//! --------------------------------------------|--------------|------------ -//! ^ ^ | | -//! |___________ | _________________________| | -//! |_________________________________________| +//! ╭──────────────────────────────────╮ +//! │ ptr | len | cap | elem_size │ +//! ╰──────────────────────────────────╯ +//! │ │ │ +//! │ ╰────────│──────────────────────────────────────╮ +//! │ │ │ +//! │ ╭────────╯ │ +//! Heap ▼ ▼ ▼ +//! ╭────────────┬─────────┬─────────────────┬──────────────┬──────────────╮ +//! value │ "hello" │ "uwu" │ │ 0 - 5 │ 5 - 3 │ +//! ├────────────┼─────────┼─────────────────┼──────────────┼──────────────┤ +//! size │ dynamic │ dynamic │ rest of alloc │ usize + meta │ usize + meta │ +//! ╰────────────┴─────────┴─────────────────┴──────────────┴──────────────╯ +//! ▲ ▲ │ │ +//! ╰────────────│──────────────────────────╯ │ +//! ╰─────────────────────────────────────────╯ //! ``` mod test;