So it turns out v8 arrays are stored contiguously, and if the array outgrows its current slot in memory, it will be reallocated in a different position in memory.
This got me wondering how about pointers. If this was in C and you reallocated the array, you have to get a reference to a new pointer!. This means that all of your code that used the old pointer will now have to use the new pointer.
This got me wondering how a JIT compiler such as v8 deals with dynamically changing variables. If you have var a = []
and then trigger v8 to grow the array size however, and it reallocates it in a different part of memory, then any code that references that a
needs to be updated to point to the new address if the JIT stuff works similarly to how I imagine assembly does. (I have very little knowledge about assembly, C, and JIT).
So I'm wondering, how v8 manages these variable references internally. How does it work.
My confusion comes at the part where it connects to the actual memory addresses. Something has to be storing the actual memory address, something is hardcoded to that. But then if it is reallocated, those references need to be updated it seems.