Custom allocator
-
GhostedGaming
- Member

- Posts: 35
- Joined: Wed Jul 02, 2025 11:46 pm
- Libera.chat IRC: GhostedGaming
Custom allocator
So I want to make a custom allocator and I was wondering if this was viable or not I know its a pretty bad diagram but you should get the gist of it. What should happen is when you allocate something it grows upwards and when you free something the top gets free which I'm kind of realizing that this is pretty bad design but I just want other opinions. I',m going to make a frame allocator and I want it to kind of grow upwards and I want to be able to free the pointer I want, now I haven't made a stack allocator before but I'm pretty sure it is how it sounds where it grows down.
Last edited by GhostedGaming on Tue Mar 24, 2026 11:00 am, edited 1 time in total.
-
GhostedGaming
- Member

- Posts: 35
- Joined: Wed Jul 02, 2025 11:46 pm
- Libera.chat IRC: GhostedGaming
Re: Custom allocator
And yes I know there's 3 used frames I just forgot to give the second one a page
-
GhostedGaming
- Member

- Posts: 35
- Joined: Wed Jul 02, 2025 11:46 pm
- Libera.chat IRC: GhostedGaming
Re: Custom allocator
Also realizing I shouldn't' do LIFO I should have it find the ptr I want to free and free it that way
-
Octocontrabass
- Member

- Posts: 6275
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Custom allocator
I don't think you'll get useful feedback if you don't explain how your allocator works or how you intend to use it.
Re: Custom allocator
As Octocontrabass mentioned, without some documentation, there isn't going to be much feedback on your implementation.
However, I created a simple memory allocator a while back that is easy to implement and targets the projects that are just starting out. You might want to have a look.
Here are some ideas that you might want to take into mind.
Ben
However, I created a simple memory allocator a while back that is easy to implement and targets the projects that are just starting out. You might want to have a look.
Here are some ideas that you might want to take into mind.
- For an OS, you will need to manage Virtual addresses and Physical addresses.
- Depending on your OS's design, you may need to manage multiple heaps, one or more per task, and one or more for the kernel.
- A majority of allocations will be allocated and then shortly freed. These allocations may be very similar in size. Therefore, as my example shows, save the last freed area so that when the next request is made, using this information, you might be able to quickly allocate the request and return. No need to search for a new available area.
- Not included with my example, but you might want to include a "trigger" page at the end of each allocation. When that page is accessed, your Page Handler can throw an exception indicating a buffer overrun. Quite useful when you allocate a stack for any given task.
- If you have a multi-processor/tasking/threading environment, you will need some kind of spinlock to make sure the memory's metadata remains in sync.
Ben
-
GNUDimarik
- Posts: 1
- Joined: Tue Oct 11, 2022 9:00 pm
Re: Custom allocator
One more solution: https://github.com/GNUDimarik/small_allocator/ I implemented it for my OS.
Another approach
Another approach