So as antisvin says, our current approach allocates heap roughly from fast to slow, and from small to big, on a first come first serve basis. So allocating high access frequency memory first would already go a long way to optimising it, for us at least.
However to fully optimise the memory layout the allocator would have to know in advance what all the required allocations are, and their frequency.
It then becomes a fairly complex optimisation, which still won’t yield perfect results, because of a number of additional complications:
- asymmetric read/write/erase times
- variations in read (or write) block sizes
- fifo sizes, burst reads, L1 cache, pipelines…
And then to consider that there are many different potential memory types: CCM, SRAM, SDRAM, memory mapped QSPI flash, SD cards…
The ideal solution would take all this into account, preferably at compile time
Meanwhile I think what we have is pretty good.
To refine it we could either:
- sequence allocations by priority (higher access time first), or
- add a pre-allocation callback which tells the memory manager what the access frequency and allocations are
The first option could be done either as Stas suggests by letting the memory manager decide the priority, or simply do it by some agreed algorithm. But it probably requires the calling code to do a lot more heavy lifting.
Second option might be less work: all the allocations could be called through twice, first as a dry run to tell the mem manager what is coming (including the access frequency and any other available metadata, like write-once or write-many). The second run would just have to be done in the same order, then the custom memory manager can allocate each one having already decided where to put it.
(Either way, memory would have to be allocated to manage the allocations )
I don’t know how feasible either is from the FAUST point of view.