[erlang-questions] "erl_drv_output_term" vs "driver_output_binary" ?

Frank Muller frank.muller.erl@REDACTED
Fri Jul 21 12:00:42 CEST 2017


Thanks Raimo. I'll stick with "driver_output_binary" for now.

/Frank

Le ven. 21 juil. 2017 à 11:44, Raimo Niskanen <
raimo+erlang-questions@REDACTED> a écrit :

> 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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170721/b23b8811/attachment.htm>


More information about the erlang-questions mailing list