I'm not 100% sure, but I do know that zero.rs requires 'the following libc functions: malloc, free, abort, memcpy, and memcmp'. So I'd imagine it's that.
I'm not 100% sure, but I do know that zero.rs requires 'the following libc functions: malloc, free, abort, memcpy, and memcmp'. So I'd imagine it's that.
I have not yet looked at Rust's code, but I guess it is required for some bootstrapping code.
If targeting direct hardware, any CS student should have learned how to implement a memory allocator on their compiler design, data structures or OS classes.
Back when I graduated, this would be a home work exercise.
If you want to implement a high performance memory allocator that works under pressure in a multi-core context, then yes it is complex to implement.
Now something that allocates/releases memory with a general purpose algorithm? That is quite simple and many compiler design books even provide such examples.
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.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa36...
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).
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.
None of those four functions use syscalls, nor are any of them simple to implement efficiently in assembly.
Consider that memcpy, under GCC,
* generates different code based on any known alignment of the source or destination
* generates simpler code if the size is known at compile time
* generates only register accesses if one or both of the arguments live in registers
* is elided entirely if GCC determines that it may do so safely
The other three have similar complex behavior. The Rust developers didn't use them just because they were too dumb to know how to write a for loop in assembly.
Anyone with compiler development experience can implement them without much trouble, hence simple.
Sadly that is a skill many seem to lack nowadays.
They can grok HTML5 page full of JavaScript stuff, but then mix language with implementation, think that strong typing is only possible with VM based languages and faith at the look of Assembly code.
Msvcrt.dll began shipping as part of the OS around the Win2K/XP timeframe, IIRC.
This is 100% correct, many of the real syscalls are located in Ntoskrnl, while kernel32.dll is actually part of the Win32 subsystem, given the personalities feature from Windows.
So you could be using another subsystem.
However, given that the POSIX and OS/2 subsystems are no longer supported, the only available subsystem is Win32.
Metro is another matter as it uses another architecture not based on the subsystems mechanism.
But in the end these are all OS APIs, not language runtimes.