Terms of type binary are accessed with the help of struct type ErlNifBinary, which contains a pointer (data) to the raw binary data and the length (size) of the data in bytes. Both data and size are read-only and are only to be written using calls to API functions. Instances of ErlNifBinary are, however, always allocated by the user (usually as local variables).
The raw data pointed to by data is only mutable after a call to enif_alloc_binary or enif_realloc_binary. All other functions that operate on a binary leave the data as read-only. A mutable binary must in the end either be freed with enif_release_binary or made read-only by transferring it to an Erlang term with enif_make_binary. However, it does not have to occur in the same NIF call. Read-only binaries do not have to be released.
enif_make_new_binary can be used as a shortcut to allocate and return a binary in the same NIF call.
Binaries are sequences of whole bytes. Bitstrings with an arbitrary bit length have no support yet.