easy to use memory allocator for single-threaded 64-bit OS

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
antoni
Member
Member
Posts: 61
Joined: Sun May 24, 2020 9:11 am
Location: /dev/null

easy to use memory allocator for single-threaded 64-bit OS

Post by antoni »

Writing my operating system I have come to such a point that I have to use malloc. Unfortunately, I don't know how to start writing memory allocator at all, so I decided to integrate another one with my OS. liballoc looked cool and was easy to use. However, I saw a thread on this forum in which it was written that it doesn't work properly with 64-bit systems. Other allocators listed in this article - https://wiki.osdev.org/Memory_Allocation are difficult to integrate.

Are there any other easy to use memory allocators not mentioned in this article? I don't need it to be cool, it can even be slow, unstable and use a lot of memory, my OS doesn't even have multitasking yet. I just want it to be simple and easy to use.
User avatar
iansjack
Member
Member
Posts: 4834
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: easy to use memory allocator for single-threaded 64-bit

Post by iansjack »

Both simple slab and buddy allocators are fairly easy to implement. Here's one link to a slab allocator implementation: http://3zanders.co.uk/2018/02/24/the-slab-allocator/

With a little Googling you can find other implementations and simple buddy allocators. This is a lot easier than it first appears to be. I'd recommend that you experiment with a simple application in Linux (or whatever your development platform is) allocating memory from a fixed array of bytes; you can then easily integrate it into your OS. That way you'll be able to run it in a debugging environment to ensure that it works correctly (and that you understand how it works).
Post Reply