5 ms·
Each person can take their own meaning away from this, but for me the most impressive part will always be @kentonv's hand-rolled libc replacement: https://githu
by zackbloom 8y ago
Each person can take their own meaning away from this, but for me the most impressive part will always be @kentonv's hand-rolled libc replacement: https://github.com/cloudflare/cloudflare-workers-wasm-demo/blob/master/bootstrap.h https://github.com/cloudflare/cloudflare-workers-wasm-demo/b...
- jgrahamc 8y agoYou're no C programmer, Zack. Anyone who's done any real C programming has implemented their own malloc.
- geofft 8y ago(Is this an in-joke I'm missing or something?)
- Smerity 8y agoIt's polite ribbing amongst work colleagues where an engineer at Cloudflare (@zackbloom) offers praise to a colleague (@kentonv) for a mighty project (libc replacement) and Cloudflare's CTO (@jgrahamc) jokes that the project isn't hardcore enough ;) tldr; Appears very much an in-joke between work colleagues at Cloudflare :)
- jgrahamc 8y agoCorrect. Not so much an in-joke. I was just surprised Zack thought implementing your own libc was amazing. But I'm an old fart C/assembly programmer so YMMV.
- zackbloom 8y agoHaving the top-comment doesn't lie, THE PEOPLE ARE WITH ME! Also, is there a badge or sash I can get somewhere saying "Not a Real C Programmer"?
- oso2k 8y agoI concur on the malloc sentiment.
- 1_player 8y ago// Really trivial malloc() implementation. We just allocate bytes sequentially from the start of // the heap, and reset the whole heap to empty at the start of each request. extern byte __heap_base; // Start of heap -- symbol provided by compiler. byte* heap = NULL; // Current heap position. void* last_malloc = NULL; // Last value returned by malloc(), for trivial optimizations. void* malloc(size_t n) { last_malloc = heap; heap += n; return last_malloc; } Am I missing something? How can this work? __heap_base is never used, so first malloc returns a pointer to (void * )NULL; Shouldn't it be: byte *heap = &__heap_base; or something to that effect? I haven't read the rest of the code, nor know how WebAssembly works, but I can't make sense of that snippet.
- Arnavion 8y agohttps://github.com/cloudflare/cloudflare-workers-wasm-demo/blob/a153279d3ba17b19aa25b0afd329515f5412077b/main.c#L31 https://github.com/cloudflare/cloudflare-workers-wasm-demo/b... // init() is called from JS to allocate space for the image file. byte* init(size_t image_size) { // Reset the heap to empty. (See malloc() implementation in bootstrap.h.) heap = &__heap_base;
- citilife 8y agoEveryone who's in CS at UIUC has to write their own libc replacement: http://cs241.cs.illinois.edu/malloc.html http://cs241.cs.illinois.edu/malloc.html There is (or at least was) a score board you can compare against. By the end of the MP, there are usually handful beating libc. The thing is.. libc is battle tested, so I'd always trust it over a hand rolled solution. It's always interesting to see improvements though (usually at a cost).
- tyingq 8y agoTrue enough, but if you follow the link in GP, it's not really a libc replacement. For example, free() is a no-op. It's a drastically small subset of libc.
- weberc2 8y ago> libc is battle tested I'm confused; isn't libc an interface and not an implementation?
- tejasmanohar 8y agoOP probably means glibc