[erlang-questions] "erl_drv_output_term" vs "driver_output_binary" ?
Raimo Niskanen
raimo+erlang-questions@REDACTED
Fri Jul 21 11:44:50 CEST 2017
On Fri, Jul 21, 2017 at 09:11:24AM +0000, Frank Muller wrote:
> Hi there,
>
> I would like to know the difference between the two calls.
>
> My linked-in driver has to send big (~4MB in average) binaries to the
> Erlang owning process.
>
> 1. Which call is better suited from that ?
driver_output_binary(port, NULL, 0, bin, offset, len) will be received by
the owning process as {Port,{data,Bin}}. A containing integer list can be
added using hbuf != NULL.
erl_drv_output_term(port, term, n) will be received by the owning process
simply as Term. This involves parsing the term in ErlDrvTermData[] format
to be able to produce any term.
> 2. Does every binary gets copied or just reference counted?
Binaries from a driver gets reference counted with either of these APIs.
> 3. Any better alternative to use?
I think these are fairly equivalent except that one produces a term on a
predefined format.
> 4. Anything else I should be aware of?
If your driver needs the binary after sending it to Erlang it will have to
increment the reference count itself, and free it later after decrementing
the reference count.
The driver can not change the data in the binary after sending it to
Erlang. That has very undefined consequences.
>
> Many thanks...
> /Frank
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list