Port driver communication witout copy of binaries
Romain Lenglet
rlenglet@REDACTED
Wed Mar 29 05:29:40 CEST 2006
Raimo Niskanen wrote:
> What you really want to do can not be done (as far as I know)
> but you might get it done with some tricks...
>
> To avoid copying your driver must implement the
> ->outputv() entry point and you must send it I/O lists
> being lists of binaries (might even be an improper list,
> that is a binary in the tail). You will have to map
> your tuples into that.
>
> If you send [1,<<2,3,4>>,5,6|<<7,8>>] to the driver,
> void (*outputv)(ErlDrvData drv_data, ErlIOVec *ev) will get:
>
> ev->iov[0].iov_len = 1;
> ev->iov[0].iov_base -> {1};
> ev->binv[0] = NULL;
> ev->iov[1].iov_len = 3;
> ev->iov[1].iov_base -> ev->binv[1]->orig_bytes;
> ev->binv[1]->orig_size = 3;
> ev->binv[1]->orig_bytes = {2,3,4};
> ev->iov[2].iov_len = 2;
> ev->iov[2].iov_base -> {5,6};
> ev->binv[2] = NULL;
> ev->iov[3].iov_len = 2;
> ev->iov[3].iov_base -> ev->binv[3]->orig_bytes;
> ev->binv[3]->orig_size = 2;
> ev->binv[3]->orig_bytes = {7,8};
>
> approximately, excuse my syntax :-)
>
> Binaries will be binaries and intermediate bytes
> will be loose vectors. If your driver wants to
> hang on to the data, it will have to use the
> reference count in the binary to avoid premature freeing.
Very nice! Using lists is OK for me.
I don't have to stick to tuples, I used tuples only to explain my
problem.
> To send data back without copying your driver will
> have to use driver_outputv() and it arrives to erlang as
> a header list of integers followed by a list of
> binaries. Conversion to tuple format will have to
> be done in erlang.
Yes, I wanted to use such functions, but I was not sure if
binaries were copied.
> Keep on dreaming...
>
> Have a look at efile_drv.c in the sources...
Thanks a lot, I have a little hope now to do things cleanly. :)
--
Romain LENGLET
More information about the erlang-questions
mailing list