Skip to content

Commit 0415950

Browse files
committed
Add pointer dereference callout and move defer loop warning out of code block
1 parent 50e8944 commit 0415950

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

basics.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,11 @@ <h2>Pointers</h2>
714714
}</pre>
715715
</div>
716716
</div>
717+
718+
<div class="callout tip">
719+
<span class="callout-icon">💡</span>
720+
<div>You dereference a pointer when you need to <strong>read or write the value it points to</strong> — not the address. Common reasons: mutating a caller's variable from inside a function, sharing a single large struct without copying it, or building linked data structures where nodes reference each other.</div>
721+
</div>
717722
</section>
718723

719724
<!-- ── 4. RUNES ──────────────────────────────────────────────── -->
@@ -1130,10 +1135,14 @@ <h2>Defer</h2>
11301135
}
11311136
<span class="fn">double</span>(<span class="num">5</span>) <span class="cmt">// 10</span>
11321137

1133-
<span class="cmt">// Avoid defer inside a tight loop — each adds overhead and they</span>
1134-
<span class="cmt">// don't run until the function returns, not the loop iteration</span></pre>
1138+
</pre>
11351139
</div>
11361140
</div>
1141+
1142+
<div class="callout warn">
1143+
<span class="callout-icon">⚠️</span>
1144+
<div>Avoid <code>defer</code> inside a tight loop. Each call is registered separately and none of them run until the enclosing <em>function</em> returns — not at the end of each iteration. This leaks resources and adds overhead proportional to loop count.</div>
1145+
</div>
11371146
</section>
11381147

11391148
<!-- ── 10. PANIC & RECOVER ───────────────────────────────────── -->

0 commit comments

Comments
 (0)