craftinginterpreters
craftinginterpreters copied to clipboard
Chapter 14: Usage of `oldSize` parameter to reallocate()
After finishing jlox, I'm onto clox – really love this style of writing, drawings, the exercises and all!
Stumbled upon the oldSize parameter passed to reallocate; I don't see why since we only make use of newSize to check if block should be freed, or otherwise using newSize to grow/shrink our existing block. Quite confused here. Am I going crazy? Thanks.
Peeked a few chapters forward, where it will indeed get usage. Maybe notify reader about this?
^ This
The relevant passage in chapter 14 reads like oldSize matters to the implementation:
The interesting cases are when both
oldSizeandnewSizeare not zero.
I was very confused that oldSize is actually unused in this chapter. @munificent could you please add a warning note about this or remove the parameter until it is used later in the book?
I just read this chapter and had the same comment :D My understanding is that the realloc call will be able to get the oldSize from the book keeping mentioned shortly after. Is that correct? If that's the case it would be good to add a comment to explain this.