Closed edilmedeiros closed 3 months ago
So I did a little investigation here and I believe I'm explaining this slightly incorrectly, though the general idea is still the same.
This line for example:
println!("transaction_bytes memory address before reading {:p}", transaction_bytes);
will print the memory address of the internal buffer (the heap location), not the structure itself. If we want the structure itself, we'd have to add the &
in front and print the memory address of &transaction_bytes
.
This makes sense since when this memory address updates, it's consistently 4 greater than the previous memory address.
So I updated the two diagrams that we can use to show what's going on here. I don't think the transaction_bytes
actually gets updated to point to the new bytes_slice
. That bytes_slice
structure remains the same and simply points to a new location on the heap.
These are the two diagrams I have. Let me know what you think.
Here is a PR I made to correct that explanation. Included the diagrams as well: https://github.com/sb1752/bitcoiner-intro-to-rust/pull/26
The new diagrams are a huge improvement. I tend to be more verbose and explain the figures I add in my texts anyhow, but I don't want to disturb your style. Based on people's difficulties and feedback, do you believe the diagrams are enough or there are more concept they are finding hard to grasp?
Yeah I'm not sure. I think the diagrams might do a lot of heavy lifting though. They def helped me quite a bit when reading the Programming Rust book.
I can see people getting confused with this, but I believe you did a great job explaining the copy of references. I tried to expand a bit and explain step by step what is happening. Please see the individual commits, in particular the top one.