craftinginterpreters icon indicating copy to clipboard operation
craftinginterpreters copied to clipboard

Chapter 14: Usage of `oldSize` parameter to reallocate()

Open irvall opened this issue 5 years ago • 4 comments
trafficstars

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.

irvall avatar Apr 01 '20 22:04 irvall

Peeked a few chapters forward, where it will indeed get usage. Maybe notify reader about this?

irvall avatar Apr 01 '20 22:04 irvall

^ This

daneelsan avatar Jan 24 '21 22:01 daneelsan

The relevant passage in chapter 14 reads like oldSize matters to the implementation:

The interesting cases are when both oldSize and newSize are 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?

abelkov avatar May 23 '21 19:05 abelkov

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.

cesartl avatar May 27 '21 08:05 cesartl