Skip to content

[Exp] Allocator Redesign #40

Description

@brightprogrammer

Allocators are what provide dynamic memory allocation capabilities to programs. The default mechanism in non-freestanding libraries is to use malloc/calloc/realloc and free for allocation and deallocation paths. This allocates on heap by default. While libc's allocator is designed to be really performant in it's allocation and deallocation paths, MisraStdC is a freestanding library and we roll our own allocators.

The existing set of allocators provide different strategies for different allocation patterns. I however see an issue with this. The existing implementation only allows allocation on heap, meaning communicating with kernel, when let's say user code might want to use a stack buffer or a statically allocated buffer as a backing buffer for allocators, given they know the exact memory usage and just want to use an allocation pattern over it.

The idea is to split existing allocators into two axes :

  • The backing buffer provider
  • The allocation strategy

Pairing those two composable axes together gives you the allocators that exist together. It also provides you ways to just get a backing buffer and let you decide how to deal with it rather than trusting the provided allocators.

I tried this idea sometime back and I failed to implement it correctly. Vibecoding is too much noise mixed with very fast progress. I now believe I'm prepared for another shot at this idea. If this works, the following good things will come out of it :

  • Same allocator pattern will still be available
  • When a developer starts optimizing their code they really get the freedom to decide where the memory comes from and how it's allocated in different scenario rather than hand-rolling their own method for every case.
  • Better study of memory usage patterns in your code (hopefully, cannot know until design is complete)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestexperimenta throwaway idea, code already works

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions