Y
Hacker News
new
|
ask
|
show
|
jobs
by
anthomtb
1321 days ago
Interesting idea but how does C++ guarantee contiguous memory for a vector? I just don’t see how a data structure with an arbitrary, dynamic size can also reside in a contiguous range of address space.
3 comments
fnbr
1321 days ago
When the array is resized, it’s moved to a new contiguous block of memory: everything is copied or moved over. See:
https://stackoverflow.com/questions/8261037/what-happen-to-p...
link
frankchn
1321 days ago
Simple, you just allocate a bigger contiguous chunk of memory and copy the entire vector over when the current chunk maxes out.
link
zabzonk
1321 days ago
the size of a c++ object is fixed at compile-time
link