sporniket / ideas

My backlog of ideas, organized as a bunch of issues
0 stars 0 forks source link

[micro-controller] Configurable allocator of memory #40

Open sporniket opened 8 months ago

sporniket commented 8 months ago

A project-oriented allocator of memory engine :

The intent is that memory consumer modules are provided with such a buffer, with description (obviously the size, the start, the DMA-capability). The consumer MAY reject the buffer (undersized, not DMA-capable, whatever), but it MUST provides a way (documentation, error message, ...) to explain the reason why.

sample-ish code

Preparing and retrieving initialized buffers

BatchMemoryAllocator bmallocator ;

void setup() {
bmallocator.prepare(SlotDescriptor("video",32000,DMA_CAPABLE),SlotDescriptor("vterm",2000),END_OF_DESCRIPTORS);

//init other modules...
myVideoDriver.bindBuffer(bmallocator.get("video"));
myVirtualTerm.bindBuffer(bmallocator.get("vterm"));
//...
}

The slot description

{
  index: number,
  key: string,
  size: number, //may be greater than required (page size ?)
  flags: bitmap //for now, only DMA capability.
}
sporniket commented 1 month ago

Naming

For now, two consumer MAY ask the same slot.


enum MemorySlotFlags {
  dma = 1,
 // that's all for now, but up to 32 values:1, 2, 4, 8,...
}

MemorySlotDescriptor {
  index: uint32, //realistically, only a handfull, but you never know
  key: string,
  size: number, //may be greater than required (page size ?)
  flags: uint32 //for now, only DMA capability.
}

class MemorySlot {
  MemorySlotDescriptor *descriptor;
  void *data;
}

class MemoryProvider {
  public:
  void setup(vector<MemorySlotDescriptor*>* descriptor); // can throw MemoryProviderError : AllocationError
  MemorySlot* get(string *key) ; //can throw MemoryProviderError : UnknownSlot error
}

abstract class UserOfMemorySlot {
  public:
  void use(MemorySlot *slot);
}