Skip to content

Conversation

@hoxha-saber
Copy link

increaseCap() might create a new vector base if it needs to grow, and so we should calculate the offset first. That way, we have avoid having possibly undefined behavior from "subtracting" two pointers who point to different memory blocks. In the event that increaseCap() would resize, posn would still point to the old array (and be invalidated) whereas begin() would point the the new array, being two separate memory blocks.

increaseCap() might create a new vector base if it needs to grow, and so we should calculate the offset first. That way, we have avoid having possibly undefined behavior from "subtracting" two pointers who point to different memory blocks. In the event that increaseCap() would resize, posn would still point to the old array (and be invalidated) whereas begin() would point the the new array, being two separate memory blocks.
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

Successfully merging this pull request may close these issues.

1 participant