Closed assyrianic closed 7 years ago
probably would make sense to have the script structure utilize a data structure that stores the allocated pointer of allocated data and then returns a 32-bit integer as a handle or index to that particular allocated pointer.
At face value, it sounds as if the vector/dynamic array data structure would work best until we delete an entry which would throw off every handle/index we return.
one solution is to wrap it around a handle struct like...
typedef struct handle {
void *pHostPtr;
uint32_t uiHandle;
} Handle_t;
or I can just make yet another hashmap using int hashing instead of string hashing but that would make it awkward to search with.
A fast and promising data structure I could use is a balanced binary tree but...
Each host allocated pointer would be added to the tree if a value were to be returned and we NEED to return a 32-bit value (area in the tree?) as a handle to that pointer.
the current method to save host-side allocated pointers is currently a memleak and here's why.
To save the pointer's memory address it points to, we just push both the address and the stack address of the address right?
Well I just remembered: what would happen to the address if we destroy and then make a new stack call frame? That address is gone and thus an irretrievable memory leak.
Solution for this would probably be to make another data structure for the scripts to store allocated data and be able to retrieve/delete it when necessary.