I would like to implement a tool that generates graphs whose memory will be allocated on a data structure so called “Tape”. You can think of a Tape as an array of elements, each of which holds “Node ID”, links to its “Parent Node” as well as its “Child Nodes”.
What I am looking for is an approach in which identifying available slots in the array is cheap so that when a new node is to be added, an empty slot can be quickly identified.
And what if I implemented the Tape using a dynamic array? In the situation where the size of the array needs resizing, can I avoid copying the entire Tape over to a newly allocated array?
Anyone here has any idea ?
I assume that you want to allocate a big ‘Tape’ beforehand of e.g. thousands of nodes.
You should combine 2 concepts:
Whenever a entry on the Tape is freed, add it to the free list.
Whenever a new entry is needed in the tape:
You can also combine this with a reallocation scheme, where you keep the total allocate size of your tape and reallocate if the last used entry reaches the end of the tape.