jhpratt / num_threads

Obtain the number of threads in the current process
https://docs.rs/num_threads
Apache License 2.0
11 stars 7 forks source link

FreeBSD: Rewrite to remove heap allocation #8

Closed Freaky closed 2 years ago

Freaky commented 2 years ago

Instead of using libutil's kinfo_getproc(), call sysctl() ourselves using a stack-allocated buffer.

In addition to avoiding a heap allocation, this also avoids a second call to sysctl() - kinfo_getproc() appears to have copied a bit too much from kinfo_getallproc() and uses the dynamic-sized-sysctl pattern with a size it already knows.