View Single Post
Old 09-19-2019, 07:53 AM   #7
geek1011
Wizard
geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.
 
Posts: 2,805
Karma: 7423683
Join Date: May 2016
Location: Ontario, Canada
Device: Kobo Mini, Aura Edition 2 v1, Clara HD
Quote:
Originally Posted by NiLuJe View Post
EDIT: Huh. I was wondering about the whole fd -> path mapping, turns out getting the path from a (dir) fd is a fun game...
Short of checking what /proc/self/fd/%d points to, nothing really comes to mind... Which is somewhat iffy, so, eh, building a cache from opendir looks like a solid approach .
Yes, but unfortunately, that's where the hackiest part IMO, and the largest performance impact comes from (from the strdup allocation, in microseconds, but that's multiplied by every directory opened, so I'd estimate around a millisecond for a few tens of thousand dirs). It's also a source of potential segfaults if I make a mistake. Also, I'm not too familiar with how arrays are optimized, but at worst, that array takes a whole ~200kb of memory when empty (4b per pointer). I wish there was a native hashmap in C (I don't want to double the code to write an efficient one).

Last edited by geek1011; 09-19-2019 at 07:57 AM.
geek1011 is offline   Reply With Quote