4 ms·
Nice! As part of some work that I was doing ages ago, I had to build myself a custom libc to statically link executables that would run on Android and WebOS sin
by mmastrac 12y ago
Nice! As part of some work that I was doing ages ago, I had to build myself a custom libc to statically link executables that would run on Android and WebOS since they are both essentially ARM Linux under the hood.
You can learn a lot by writing yourself a libc. Even building a simple/stupid malloc from scratch is a learning exercise.
- jeffreyrogers 12y agoI was shocked how complicated the glibc malloc is. Here's the source for anyone interested: http://repo.or.cz/w/glibc.git/blob/HEAD:/malloc/malloc.c http://repo.or.cz/w/glibc.git/blob/HEAD:/malloc/malloc.c
- jacquesm 12y agoIt's relatively easy to make an allocator, it is really hard to make an efficient one that works well across a large variety of use cases. That's also why it can pay off big time if you know more about your use case than malloc does (and you usually do) to roll your own allocator.
- joosters 12y agoMemory management is complicated (at least, doing it well is). It's a good thing to discover as well, because it should lead to an appreciation that malloc() isn't cheap, and there can be an awful lot of work behind every single call. Besides, that code seems pretty well commented.
- coliveira 12y agomalloc is a generic allocator, it needs to worry about a lot of things that are not common. A simple allocator will work most of the time, but the devil is in the details.
- gjm11 12y agoIt's complicated, but there's quite a bit of wisdom embodied in it. It's well worth reading the code and comments carefully, if you're at all interested in memory management.
- oso2k 12y agoThat is very cool. That source public anywhere?
- mmastrac 12y agoNot right now. I just looked at it again, but it's just way too ugly to open-source without some serious work. It was cobbled together from bionic's headers with a re-implementation of enough of the standard library to get TomCrypt and file I/O calls up and running. Happy to share it privately (email in profile).
- hyc_symas 12y agoHave a look at the libc we wrote for Atari ST TOS/MiNT. Nice and small, but still mostly POSIX compliant. Nearly 30 years ago now.