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

Tim Watson watson.timothy@REDACTED
Thu May 12 22:20:42 CEST 2011


In a port driver I'm working on, I pass an iolist to driver_outputv
and on encountering a binary, need to know whether it is a ref-counted
binary or not (i.e. a so-called heap binary). The location of the
action data in the ErlIOVec depends on this apparently. I've seen some
anecdotal evidence (on the mailing list) to suggest that if the binary
is > 64 bytes it will be ref-counted, but I want to know if there is
an API (or perhaps a macro in the OTP source tree) that I can use to
determine this?

Currently I'm using a hack-around like so:

    if (hsize->xsl_size < 64) {
        data = &ev->iov[++bin_idx].iov_base[0];
    } else {
        data = ev->binv[++bin_idx]->orig_bytes;
    }

This code (taken from
https://github.com/hyperthunk/erlxsl/blob/master/c_src/erlxsl.c) seems
to work, but I'm fairly sure it's not The Right Thing To Do (TM).

Any pointers to better solutions would be much appreciated.

Cheers,

Tim



More information about the erlang-questions mailing list