I am wondering how v8 solves the problem of storing arrays in a fragmented memory. Basically, what is the array data structure in v8. I assume under the hood v8 has to deal with the problem of memory fragmentation. I have read that C allocated arrays with contiguous memory which makes sense since you are allocating it directly anyways. But with JavaScript it is dynamic so it seems you can't allocate them contiguously always.
Given memory blocks of 8 bytes free ○ and allocated ●, imagine this scenario.
○○○○○○○○○○○○○○○○○○○○○○○○○○○
Then you add an array of 5 items:
●●●●●○○○○○○○○○○○○○○○○○○○○○○
Then you add another array to a different part of memory:
●●●●●○○○○◖◖◖○○○○○○○○○○○○○○○
The question is, if you add 10 more items to the first array, how does it work:
●●●●●●●●●◖◖◖●●●●●●○○○○○○○○○
Wondering if you are keeping track of the array structure somewhere else instead of just the fact that they are contiguous (like in C).