Quote:
Originally Posted by NiLuJe
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).