NIF wishes

Hans Nilsson R hans.r.nilsson@REDACTED
Tue Dec 8 17:50:12 CET 2009


I have been playing with the NIF facility in R13B03 and I have some 
comments. The implementation is very stable, as usual with experimental 
code from Erlang/OTP!  And very fast....

I have a large binary which I pass into a nif, which processes a part of 
it and returns the result and the unprocessed part of the binary.  The 
unprocessed part is then input to the nif again and so on.

Wish 1:
Now, in the nif, to make a copy of the unprocessed part and make a new 
binary is time consuming, so some function enif_make_sub_binary(env, 
bin, from, to) would be useful.

Wish 2:
When the nif shall return a part of the binary as a string or a binary, 
the functions enif_make_atom and enif_make_string  assumes that the part 
is zero-terminated.  It is of course possible to save the character, 
write a zero, call the enif-function and then write back the original 
character, but it is of course dangerous to modify in place in a 
binary...  The alternative of copying the characters to a buffer is slow.

Therefore I'd like to have some  enif_make_string_n(env, char *p, int 
length) as well, analogous to the c-library functions strcpy and strncpy.

/Hans Nilsson



More information about the erlang-questions mailing list