Can we use allocators in freestanding target?

Hello there,

currently, I’m progressing well with my “OS” and it is already able to draw a rect in the kernel.
However, because I want to go on, I wanted to ask whether memory allocators from the standard library work in freestanding (=> kernel) target.
Personally, I don’t think that they work, but I just wanted to be sure.

Looking forwards,
Samuel Fiedler

No, you have to write your own allocator. You can use arena allocator with your own allocator though. Edit: std.heap.FixedBufferAllocator of course can be used though!


That makes sense. Thanks.

Yes, you can use allocators in the freestanding target. However, some allocator implementations depend on operating system syscalls.

As an example, one of the most useful allocators, std.heap.ArenaAllocator, uses a backing allocator and does not make syscalls directly, so it works exactly the same on the freestanding target.

std.heap.page_allocator, on the other hand, will give you a compile error if you tried to use it on the freestanding target, since it depends on mmap (posix) or VirtualAlloc (windows).