<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Mns03&#39;s Blog</title>
    <link>https://mns0327.github.io/</link>
    <description>Recent content on Mns03&#39;s Blog</description>
    <image>
      <title>Mns03&#39;s Blog</title>
      <url>https://mns0327.github.io/icon/og-image.png</url>
      <link>https://mns0327.github.io/icon/og-image.png</link>
    </image>
    <generator>Hugo -- 0.150.0</generator>
    <language>en</language>
    <lastBuildDate>Thu, 18 Sep 2025 15:13:16 +0900</lastBuildDate>
    <atom:link href="https://mns0327.github.io/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Memory Allocation in Rust: Box, Vec, and the Global Allocator</title>
      <link>https://mns0327.github.io/posts/allocate/</link>
      <pubDate>Thu, 18 Sep 2025 15:13:16 +0900</pubDate>
      <guid>https://mns0327.github.io/posts/allocate/</guid>
      <description>&lt;p&gt;This post explores how Rust manages memory through &lt;code&gt;Box&lt;/code&gt;, &lt;code&gt;Vec&lt;/code&gt;, and the global allocator, uncovering what really happens under the hood.&lt;/p&gt;
&lt;h1 id=&#34;box-and-vec-memory-allocation&#34;&gt;Box and Vec Memory Allocation&lt;/h1&gt;
&lt;p&gt;Before diving into implementation details, let’s first understand how &lt;code&gt;Box&lt;/code&gt; and &lt;code&gt;Vec&lt;/code&gt; internally use allocators.&lt;/p&gt;
&lt;h2 id=&#34;box&#34;&gt;Box&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Box&lt;/code&gt; is the simplest smart pointer in Rust. It allocates a value on the heap while making ownership explicit and safe.&lt;/p&gt;
&lt;p&gt;Under the hood, though, &lt;code&gt;Box&lt;/code&gt; is more complex than the &lt;code&gt;Box&amp;lt;T&amp;gt;&lt;/code&gt; we usually write. Here’s the actual definition:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Rust: How the Compiler Manages Lifetimes</title>
      <link>https://mns0327.github.io/posts/compiler-lifetime/</link>
      <pubDate>Thu, 11 Sep 2025 20:19:41 +0900</pubDate>
      <guid>https://mns0327.github.io/posts/compiler-lifetime/</guid>
      <description>&lt;p&gt;Most people just use lifetimes without understanding how they are implemented under the hood. So I decided to dig into the compiled binary to see how Rust actually manages lifetimes at the machine level.&lt;/p&gt;
&lt;h4 id=&#34;the-string-struct-layout&#34;&gt;The String Struct Layout&lt;/h4&gt;
&lt;p&gt;Before diving into the assembly, it helps to recall how Rust represents a &lt;code&gt;String&lt;/code&gt; internally. A &lt;code&gt;String&lt;/code&gt; is essentially a wrapper around a &lt;code&gt;Vec&amp;lt;u8&amp;gt;&lt;/code&gt;, which in turn manages a heap-allocated buffer:&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Field&lt;/th&gt;
          &lt;th&gt;Description&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;ptr&lt;/td&gt;
          &lt;td&gt;Pointer to the heap-allocated buffer&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;cap&lt;/td&gt;
          &lt;td&gt;Capacity (number of bytes the buffer can hold without reallocating)&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;len&lt;/td&gt;
          &lt;td&gt;Current length (number of bytes used)&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/rust-lang/rust/blob/master/library/alloc/src/string.rs&#34;&gt;alloc/src/string.rs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/rust-lang/rust/blob/master/library/alloc/src/vec/mod.rs&#34;&gt;alloc/src/vec/mod.rs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/rust-lang/rust/blob/master/library/alloc/src/raw_vec/mod.rs&#34;&gt;alloc/src/raw_vec/mod.rs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;move-value&#34;&gt;Move value&lt;/h2&gt;
&lt;p&gt;In Rust, ownership ensures that when a value is passed to a function by move, the caller loses access to it. This guarantees that memory can be safely freed once the function finishes. Unlike in C, where the programmer decides when to free memory, Rust enforces this through the type system.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
