Don't think I'd call it a hot loop. It is called once for every process on a system as often as the user polls. If you're thinking something like "top" that'd be every few seconds. So the process iteration is the bigger impact, and leaving open the opportunity for multithreading would challenge memory re-use. I suspect all the Reflection overhead of JNA (and multiple reads to fetch each field) would be a bigger impact.
I ended up starting down a different path before seeing this reply and it seemed to work well, so I'll probably leave it. My approach:
- created an enum with the values representing the structure fields. Each enum also carried an integer of the size in bytes.
- manually adjusted padding for 8-byte alignment boundary
- created a static EnumMap to iterate the enum and store offsets based on the byte sizes
Then, for each process when queried:
- To query the values, read a RandomAccessFile into a ByteBuffer via a FileChannel/ByteArrayOutputStream
- Used the ByteBuffer getters (using the enum size to know which one) at the appropriate offsets from the EnumMap to fetch the values.
Related to your reply, I did end up using libc.pread() later, to read strings from the process address space into memory for a different purpose. Perhaps my followup question on that should be a new thread, though.
Dan