Our existing list implementation using Vec under the hood. This causes several issues with the long term health of the system.
We can't accurately track the size of the heap as we're making allocation viaVec instead of Allocator
We also need to do a double pointer deref to get to the actual data.
Additionally we'll want to eventually do similar with Map and to do that we'll need a collection which is GC managed.
Solution
Create a new container GcList which is a resizable array. Like GcArray it contains it's header and length information inline with it's data. Additionally GcList contains a capacity field.
When an operation like push is applied to GcList that would requires a a resize the following occurs
We check if we have sufficient capacity for the operation
If not we us the provided hooks allocator to create a new list with double the capacity
The elements of the old list are copied into the new list
We mark the MSB of the capacity as set taking advantage of the fact we would never use 64 bits of len capacity. We may need a different strategy for 32 bit systems as it is somewhat more likely we may need something over ~2B for an index
The len field is written as a pointer to the new list
RIght now in the case of multiple resizes we would need to go through multiple pointers to get to do data which defeats the directness advantage. I'll follow up this PR with another we we introduce a mechanism for a native function to signal for an argument to be changed.
Problem
Our existing list implementation using
Vec
under the hood. This causes several issues with the long term health of the system.Vec
instead ofAllocator
Additionally we'll want to eventually do similar with
Map
and to do that we'll need a collection which is GC managed.Solution
Create a new container
GcList
which is a resizable array. LikeGcArray
it contains it's header and length information inline with it's data. Additionally GcList contains a capacity field.When an operation like
push
is applied toGcList
that would requires a a resize the following occursRIght now in the case of multiple resizes we would need to go through multiple pointers to get to do data which defeats the directness advantage. I'll follow up this PR with another we we introduce a mechanism for a native function to signal for an argument to be changed.