Don’t you need to request heap space from operating system via system call?
Don’t you need to request heap space from operating system via system call?
Something else to consider is that there may not even be an operating system the program was run on.
Sure, in this case you can just implement malloc the same way a kernel implements me. My failure of understanding is when there _is_ a kernel that your program needs to interact with.
That way if you need to add new platform, it's only one place; you're shielded against weird platform bugs (Apple goes one way, Microsoft the other), so the app behaves the same; you can tweak system to your particular use.
For performance reasons (avoiding a syscall) almost all malloc implementations only use sbrk / mmap occasionally and keep the malloc calls in userspace.