Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9.40: Clarification #36

Open
xjay73 opened this issue Jun 28, 2021 · 0 comments
Open

9.40: Clarification #36

xjay73 opened this issue Jun 28, 2021 · 0 comments

Comments

@xjay73
Copy link

xjay73 commented Jun 28, 2021

Since the exercise asks what the program does, it's worth noting what the capacity will be at the end of the program instead of what it is after the program reads the words.

(a) The capacity will be at least 1,024 -- reserve sets the capacity to be enough to hold at least the specified amount. Since half-again 256 is still less than 1,024, no reallocation occurs during the resize, so the capacity stays the same.
(b) The capacity will be at least 1,024 -- half again 512 is still less than 1,024, so no reallocation occurs.
(c) The capacity will be at least 1,500 -- half again 1,000 is greater than 1,024, so reallocation occurs during the resize, changing the capacity to be at least the resize amount.
(d) The capacity will be at least 1,572 -- after reading 1,025 words, reallocation is likely to occur before reading the remaining 23 words ("likely" because it depends on whether the original allocation was 1,024 or greater than that.) The capacity after reading the full 1,048 words, then, depends on the implementation. If it's more than 1,572, the resize won't require an additional reallocation, but we know that the final capacity cannot be less than that because of the resize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant