20 Data Structures for Runtime Systems
Each data structure in a runtime solves one problem inside it. R keeps the bindings of the global environment, and of any environment new.env() creates by default, in a hash table. A work-stealing scheduler keeps each worker’s tasks in a deque. An arena hands out memory for objects that are all freed together. GNU R’s garbage collector records which objects it has reached in a mark bit in each object’s header. This corpus teaches each structure inside the runtime page that uses it, not as a generic algorithms course.
Scope of this section
A structure is easier to judge next to the problem it solves, because the same structure can be fast or slow depending on the allocation pattern and access frequency it meets. An arena allocates many small objects of similar size and lifetime quickly, and suits long-lived objects with varied lifetimes badly. That tradeoff only makes sense next to the memory manager it serves, so the structures live in the runtime pages and this page points to them.
Where this material lives instead
- Hash tables: Environments covers hashed and unhashed binding storage.
- Deques: Work Stealing covers scheduler queues and parallel task distribution.
- Arenas, pools and free lists: Arenas, Pools, and Immortal Data covers region allocation, recycling, and the immortal arena in threaded-r.
- Mark bits: Garbage Collection covers the GC bits in each object header.