1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-21 14:46:37 +02:00

Do not show trait vtables as located in the heap in memory diagram (#1882)

This diagram is misleading and I often explain that the character data
of string literals resides in the executable's static data, with vtables
working the same.
This commit is contained in:
Frances Wingerter 2024-03-06 21:22:16 +00:00 committed by GitHub
parent 976f6f6f24
commit 42f6e1186e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,29 +48,29 @@ Memory layout after allocating `pets`:
Stack Heap Stack Heap
.- - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - - - - - - - - -. .- - - - - - - - - - - - - -. .- - - - - - - - - - - - - - - - - - - - - - -.
: : : : : : : :
: pets : : +----+----+----+----+ : : "pets: Vec<dyn Pet>" : : "data: Cat" +----+----+----+----+ :
: +-----------+-------+ : : +-----+-----+ .->| F | i | d | o | : : +-----------+-------+ : : +-------+-------+ | F | i | d | o | :
: | ptr | o---+---+-----+-->| o o | o o | | +----+----+----+----+ : : | ptr | o---+---+--. : | lives | 9 | +----+----+----+----+ :
: | len | 2 | : : +-|-|-+-|-|-+ `---------. : : | len | 2 | : | : +-------+-------+ ^ :
: | capacity | 2 | : : | | | | data | : : | capacity | 2 | : | : ^ | :
: +-----------+-------+ : : | | | | +-------+--|-------+ : : +-----------+-------+ : | : | '-------. :
: : : | | | '-->| name | o, 4, 4 | : : : | : | data:"Dog"| :
: : : | | | | age | 5 | : : : | : | +-------+--|-------+ :
`- - - - - - - - - - - - - -' : | | | +-------+----------+ : `- - - - - - - - - - - - - -' | : +---|-+-----+ | name | o, 4, 4 | :
: | | | : `--+-->| o o | o o-|----->| age | 5 | :
: | | | vtable : : +-|---+-|---+ +-------+----------+ :
: | | | +----------------------+ :
: | | '---->| "<Dog as Pet>::talk" | :
: | | +----------------------+ :
: | | : : | | :
: | | data : `- - -| - - |- - - - - - - - - - - - - - - - -'
: | | +-------+-------+ : | |
: | '-->| lives | 9 | : | | "Program text"
: | +-------+-------+ : .- - -| - - |- - - - - - - - - - - - - - - - -.
: | : : | | vtable :
: | | +----------------------+ :
: | `----->| "<Dog as Pet>::talk" | :
: | +----------------------+ :
: | vtable : : | vtable :
: | +----------------------+ : : | +----------------------+ :
: '---->| "<Cat as Pet>::talk" | : : '----------->| "<Cat as Pet>::talk" | :
: +----------------------+ : : +----------------------+ :
: : : :
'- - - - - - - - - - - - - - - - - - - - - - -' '- - - - - - - - - - - - - - - - - - - - - - -'