Design Considerations

General Goals

We want users to be able to write mostly idiomatic-looking Python code which can still be used to design experiments with very precise timing between measurements

The default should both:

Therefore, a requirement is that

dynamic memory allocation

which requires malloc-style memory management and possibly reference counting,

will require explicit annotation by users.

Proposed solution

We propose to explicitly segregate code that uses dynamic memory management (DMM) from code that uses a more static form of stack-based memory (SMM) management using regions, described below.

The latter would be the assumed default, while the former would need some lightweight annotation from users.

Moreover, a type-and-effect system will be used to ensure that SMM code is safe in the following senses:

An implicit memory leak (IML) is defined as:

the unbounded accumulation of dead memory during program execution,

where dead memory is memory that is longer accessible (can no longer be accessed through reachable pointers)

Stack-Based Memory Management Through Regions

The idea is similar to previous work on region-based memory management, except that we are more stringent with making sure that memory does not leak implicitly.

Implementation Characteristics

Regions are implemented as a linked list of fixed-size buffers (FSB), which would live in a separate region of the program memory than the dynamic heap, called the FSB memory, so that FSBs can be created instantly.

Region allocation is therefore constant-time:

a check that the current FSB is not full

if it is, obtain a new one from the free list

or allocate one (by bumping the FSB memory pointer)

and a pointer bump for allocating space for the object inside the FSB

Region deallocation can be made constant too, as long as we keep a pointer to the last FSB of the region, so we can add the whole thing to the front of the free list