Excellent. Did we agree on the following, at least conceptually, as a way to relieve RAM pressure from the various modes?
-
Provide “mode buffer” allocator … with intent to replace static globals that would not be used outside the mode … effectively giving each mode 128k to play with, while reserving the other 128k for use by system bus pirate purposes.
-
upon entering a mode, all previously allocated “mode buffers” are implicitly
free()
d … ensuring a known-good starting state -
a mode may allocate memory from the “mode buffer”, with intent that this would occur during
init()
-
Aligned memory can be requested, and if non-null, the allocation will be aligned to the requested alignment.
-
No API to
free
individual allocations made from “mode buffer” memory … again, intent is to remove large static globals, not a fullmalloc()
-
Instead of
free
, an API will allow the mode to reset the state of the mode buffer to its known-good starting state (all memory free and available to allocate).
There’s a similar set of features in another MIT-licensed project I use, so I will review what API it exposes, and propose something for your thoughts.
The proposal will include up to two mode function pointers (init()
and cleanup()
), some APIs for requesting mode-specific memory, and a list of guarantees for those mode-specific memory allocators. Examples:
A. upon entering init()
, 128k of memory is generally available, aligned to at least a 4k boundary (32k in current implementation, but thought 4k should be sufficient for the API guarantee).
B. If requesting aligned memory allocation, the returned pointer is guaranteed to meet that alignment requirement. If not possible to align as requested, nullptr
will be returned.
C. There are no guarantees as to the relative values of pointer for successive allocations. A later allocation may have a pointer prior to (value less than) or after (value greater than) a prior allocation. Similarly, there is not guarantee that successive allocations will be adjoining … the memory may include overhead and/or space set aside to help debug issues. Debug builds might have compile-time options that will change the allocator behavior (etc.).