| ▲ | foobarian 2 hours ago | |
Disagree, I found malloc source useful, and writing a toy allocator especially useful because you learn about the brk() syscall which is a great breadcrumb into kernel land and a great bridge to connect the memory mapping lessons from computer architecture with application code. | ||
| ▲ | netbsdusers 9 minutes ago | parent | next [-] | |
These days brk and sbrk have fallen from grace (and I think even some Unix-likes no longer provide them as general mechanisms, at least I don't think macOS does) - mmap is usually favoured. | ||
| ▲ | stevekemp an hour ago | parent | prev | next [-] | |
Depending on how low-level you're going, you don't even need to call brk. My toy stop/copy GC and allocation routines just have this:
Of course there are other syscalls involved in my compiler/runtime, but for memory allocations the static area sufficed for me. | ||
| ▲ | Joker_vD 22 minutes ago | parent | prev [-] | |
> and writing a toy allocator especially useful because you learn about the brk() syscall Nobody in their right mind (except musl) use brk(2) nowadays; mmap(2) is pretty much universally accessible, and brk() has been non-portable for more than 20 years already (POSIX ditched it in 2001) anyhow. For goodness sake, stop keeping this stupid API from VM-lacking PDP-7 alive, and let it go away! Edit: also, I have no idea how musl even uses it:
That's... not what brk() returns; it returns 0 on success and -1 on failure. Huh? | ||