News for hackers. Stuff that matters.
Re:Removing garbage collection from the Rust language by ahomescu1 on Monday June 03, 2013 @06:45PM (#5816576)
> If you are targeting an existing OS, malloc/free can be simple wrappers to OS syscalls for memory allocation.

Not really, there's no such thing as malloc/free syscalls. On Linux, you have mmap/munmap (at page granularity) and brk/sbrk (which only extend the current heap). You could implement malloc as either a mmap() of one or more pages, or by using sbrk() to extend the heap by exactly the memory you need, but then freeing that memory becomes much harder.

Re:Removing garbage collection from the Rust language by srgpqt on Monday June 03, 2013 @08:27PM (#5816973)
To take the example of Windows, wouldn't this qualify as a malloc/free syscall equivalent?

http://msdn.microsoft.com/en-us/library/windows/desktop/aa36...

Re:Removing garbage collection from the Rust language by marshray on Tuesday June 04, 2013 @04:39AM (#5818296)
In fact, I believe modern versions of msvcrt.dll just call HeapAlloc(GetProcessHeap(), ...) in the usual case.
Re:Removing garbage collection from the Rust language by pjmlp on Tuesday June 04, 2013 @01:10AM (#5817840)
That is what I meant by OS syscalls.

Should I write a full tutorial on an HN post how to write memory allocators when anyone can easily search for one?

Re:Removing garbage collection from the Rust language by ahomescu1 on Tuesday June 04, 2013 @04:31PM (#5821944)
> Should I write a full tutorial on an HN post how to write memory allocators when anyone can easily search for one?

No, but a memory allocator is more that "simple wrappers". My point was that OS kernels (Linux/BSDs at least) don't actually provide malloc/free as syscalls, and that you need to implement an allocator in userspace if you want these functions (even if it's a trivial allocator that wastes memory).

Re:Removing garbage collection from the Rust language by pjmlp on Wednesday June 05, 2013 @03:17AM (#5824153)
Of course they don't, why should they?!

malloc/free are part of the C language runtime, not OS syscalls.

A compiler writer can build the memory allocator on top of what the OS provides as syscalls or take a shortcut and use the C runtime library instead while adding a dependency to it.

I never mentioned malloc/free were syscalls.