4 ms·
I don't like this article. It comes across as being written with the intent of highlighting the elevation the author's status as a 'low-level wizard', while con
by ShroudedNight 7y ago
I don't like this article. It comes across as being written with the intent of highlighting the elevation the author's status as a 'low-level wizard', while conveying as little as possible to the ignorant reader. From the scattered aspects of memory management it covers to it uses of unexplained magic numbers in its code examples, it comes across more as an unsolicited secret handshake than cogent, empathetic attempt to elevate others in the practice.
Disclaimer: I had a hard time following this article. I'm also (ostensibly anyway) not the target audience. I was at one point the primary person responsible for the memory management in the JIT compiler[1] used by OpenJ9, though I haven't done that for a couple of years now.
[1] That is, the memory used by the JIT compiler itself, not its interactions with the garbage collector.
- SlowRobotAhead 7y agoI am the target audience. I get exactly what he’s going for but found a different gripe. I really dislike his coding style! It’s written to be “short” in favor of clear. I see what the code does, but not necessarily his intent. void*page_alloc(unsigned long long bytes) { void *x; for(;;) { x = mmap(0, bytes, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if(x != MAP_FAILED) return x; out_of_memory(); } } For embedded I stoped using “unsigned long long” in favor of uint64_t. He spends all those extra characters but can’t put a space in the void pointer function definition?
- EdSchouten 7y agoIn this case it also makes most sense to use size_t, right?
- SlowRobotAhead 7y agoDepends. If you use size_t all the time, you may forget or have someone else forget that another system isn’t the same. If you always use uint8_t or int64_t etc there is no ambiguity. If I intended this to be an 32bit var, it will be regardless if who is compiling it.
- EdSchouten 7y agoBut this is an allocation function, where the amount of data to be allocated is specified in bytes. That must surely use size_t. Imagine the case where 128 bit systems become popular and you want to use this function to allocate 2^70 bytes of memory. Using uint64_t here would be invalid in that case.
- SlowRobotAhead 7y agoIf you’re going to allocate like that you could use 8s and get any multiple you like, no? I’ll give you that there are times for performance you want the native system type. But I would still prefer to use uint32_t and specify this was optimized for a 32bit system.
- earenndil 7y agoLikely targeting c89, which doesn't have the fixed-size ints (nor size_t, as the sibling suggests).
- ShroudedNight 7y agoMy recollection was that size_t and ptrdiff_t were present in c89. size_t was the type yielded by sizeof. This draft appears to corroborate my recollection: http://port70.net/~nsz/c/c89/c89-draft.html#3.3.3.4 http://port70.net/~nsz/c/c89/c89-draft.html#3.3.3.4
- geocar 7y agoApologies! I usually typedef long long J;typedef unsigned long long U; and that makes it a bit shorter, but I wanted each example to compile, and not to get bogged down on typedefs.
- einpoklum 7y agoIf you use this kind of typedefs, most people reading your code will kind of hate you... either that or you're targeting the Internationl Obfuscated C Code Contents [1]. [1] - https://www.ioccc.org/ https://www.ioccc.org/
- saagarjha 7y agoPerhaps this might help explain their reasoning: https://news.ycombinator.com/item?id=22010590 https://news.ycombinator.com/item?id=22010590
- SlowRobotAhead 7y agoI didn’t downvote you, but your link contained this... and I considered it. ZI http(I d,I f,C*p,I r,I*sd){I i,o=0,b=0,s=0,w=0,g=0,e=0,c=0,cf=1,m=0;K q=0,a=ktn(11,0),v=ktn(0,0); for(i=b=0;i<r;++i){switch(p[i]){ case'\n':if(!e)e=i;if(!q){q=kpn(p+w,g-w);if('\r'==(cf=p[i-1]))cf=p[i-2];}else if(!c){w=!!strchr("kK1",cf);if(!o)sc(d,0,sd);else if(w){if('g'==o)cwrite(f,OK("200","keep-alive")BLANK);else cwrite(f,OK("204","keep-alive")END204);}else{if('g'==o)cwrite(f,OK("200","close")BLANK);else cwrite(f,OK("204","close")END204);close(f);}a=k(o?-d:d,"dash",knk(2,q,xD(a,v),0),0,0);b=i+1;if(!o){if(!a){poop(f);R 0;}if(10!=a->t){r0(a);poop(f);R 0;}writer(f,kC(a),a->n);r0(a);if(!w)close(f);}if(b==r)R 1;q=0;o=0;a=ktn(11,0),v=ktn(0,0);}else{if((c-m)==10&& !strncasecmp(p+m,"connection",c-m))cf=p[s];js(&a,sn(p+m,c-m));jk(&v,kpn(p+s,e-s));}w=e=g=s=c=0;m=i+1;break; case' ':case'\t':case'\r':if(w&&!g)g=i;if(s==(e=i))++s;break; case':':if(!c)s=1+(c=i);break; case '/':if(!w)w=i+1;case '?':case '&':if(r>=(i+4)&&p[i+1]=='f'&&p[i+2]=='=')o=p[i+3];default: e=0;break;}}if(a)r0(a),r0(v);if(q)r0(q);R b;} Thanks, I learned about something I absolutely hate.
- geocar 7y ago> unexplained magic numbers Which "magic number" do you think was left unexplained? I thought I had got them all.
- vardump 7y ago> It comes across as being written with the intent of highlighting the elevation the author's status as a 'low-level wizard', while conveying as little as possible to the ignorant reader. Technical article for a technical audience, namely POSIX C programmers. There's no secret handshake or subtext to elevate the author.
- saagarjha 7y agoYou can be a POSIX C programmer and have no idea what sbrk is. (In fact, it was deprecated very early and removed in POSIX 2001.)