[erlang-questions] Determine if a binary is ref-counted in port driver code

Tim Watson <>
Fri May 13 13:06:45 CEST 2011


> From http://www.erlang.org/doc/man/erl_driver.html
>
> "The ErlDrvBinary structure is a binary, as sent between the emulator and the driver. All binaries are reference counted"
>
> Also, this and the following functions might be of use:
> http://www.erlang.org/doc/man/erl_driver.html#driver_binary_get_refc

Thanks for the timely response Gustav. That seems to refer to the
ErlDrvBinary that is passed between the emulator and the driver. When
an iolist of binaries is passed to port_command, for each entry in the
ErlIOVec passed to driver_outputv, the data will only be stored in the
binv field *if* the binary is not heap allocated. If it is a
small/heap-allocated binary, then the data will appear in the iov
field instead. In this (latter) case, there is no ErlDrvBinary to
examine and the data is present in the iov_base field of the SysIOVec
stored in ev->iov[index].

What I'm trying to ascertain is whether or not there is a way to tell
whether a given entry in the ErlIOVec structure will reside in the
binv or iov field. Have I misunderstood the way this works? The
documentation is a little scant, but this thread appears to cover the
issue to some extent:
http://erlang.org/pipermail/erlang-questions/2006-August/021904.html.



More information about the erlang-questions mailing list