Port driver memory free

Casper casper2000a@REDACTED
Wed Mar 16 07:43:20 CET 2005

Hi All,

There are 2 parameters, **rbuf and rlen in Port Driver entry "control. In
PORT_CONTROL_FLAG_BINARY mode, I should pass a driver_binary in **rbuf.
Usually rlen is 64, which mean **rbuf has 64 bytes, if I need to use that
without creating a new ErlDrvBinary. My questions are,

1. If my final ErlDrvBinary size is < 64 bytes and I use **rbuf without
allocating a new ErlDrvBinary, should I still call driver_free_binary or
driver_free to free that **rbuf memory before "control" function returns?

2. If my final ErlDrvBinary size is > 64 bytes and I allocate a new
driver_binary and assign to **rbuf, what will happen to the previous 64
buffer which was in **rbuf? Will the port or erlang garbage collecter free
that? Or do I need to free it inside the "control" function by calling
driver_free_binary or driver_free?

3. I (2) above, what will be the case if I use driver_realloc or
driver_realloc_binary? Will the previous 64 byes get released?

4. I (2) above, I still need to call driver_free_binary to free the newly
created driver_binary inside "control" function, correct?

5. If I call "set_port_control_flags(dd->port, 0)" to set the port output to
non-binary, do I need to free or clear the non-used space of **rbuf?

6. In above cased which free function, driver_free_binary or driver_free and
which allocation function, driver_alloc, driver_alloc_binary,
driver_realloc, driver_realloc_binary should I use?

Thanks in advance!
- Eranga

More information about the erlang-questions mailing list