rust-lang / rust-lang/rust-by-example

19.1 Box, stack and heap - Wrong output

Open
#1,648 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Handlebars
Stars
8.1k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

From example here
we have output

Point occupies 16 bytes on the stack
Rectangle occupies 32 bytes on the stack
Boxed point occupies 8 bytes on the heap
Boxed rectangle occupies 8 bytes on the heap
Boxed box occupies 8 bytes on the heap
Unboxed point occupies 16 bytes on the stack

Boxed point don't occupies 8 bytes on the heap. Pointer to point occupies 8 bytes on the stack, point on the heap occupies 16 bytes.

Boxed rectangle don't occupies 8 bytes on the heap. Pointer to rectangle occupies 8 bytes on the stack, rectangle on the heap occupies 32 bytes.

First box occupies 8 bytes on stack, second box occupies 8 bytes on heap and point occupies 16 bytes on heap.

From current text it looks if you put 2MB on heap they will only take 8 bytes on heap, because rectangle who is 32 bytes only take 8 bytes on heap.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust by Example std/box.html example linked in the issue and compare its output and explanation of stack and heap sizes with the reported behavior. Update the wording and output so pointer sizes are distinguished from the sizes of boxed values, then verify the example’s displayed output.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.