As far as I’m aware and I used port drivers in GRiSP extensively when statically linked NIFs were still not implemented, there is currently nothing anymore you can do with port drivers which can’t be done with NIF (better).
I did a cursory check of lists
module implementation and found that all functions which take a fun as a argument are implemented in pure Erlang. That shows us two things:
- its not even possible for BIFs to call a fun (or not easy), otherwise I would have looked at these implementations to see how we could add the functionalities for NIFs
- If its fast enough for
lists
its probably fast enough for your application
Another look at ets:foldl/3
implementation which is similar to your intended implementation and needs a way to iterate through all elements in an ets
table and call a fun
on them:
You can see it uses ets:first
and ets:next
to iterate through the table and calls the fun from Erlang. Thats exactly how you will want to implement this.