[erlang-questions] Port Driver, outputv, binaries.

Tony Rogvall tony@REDACTED
Thu Dec 10 14:30:12 CET 2009


Hi!

On 10 dec 2009, at 12.20, Matthew Sackman wrote:

> Hi Tony,
> 
> Thank you very much for your email - that's very helpful.
> 
> I have one further question:
> 
> If I construct and send a binary with port_command, can I be guaranteed
> that it'll not be split across two or more different binvs?
> 

My guess is that you could probably assume that a single binary
will not be split up. But how knows ;-) 

> Eg
> 
> a) port_command(Port, [<<1,2,3>>]), or
> b) port_command(Port, [<<"foo">>]), or
> c) port_command(Port, [<<"foo",0>>]), or
> 
> c) is particularly important to me because I've noticed that if you send
> a string down, it doesn't get null terminated, so sticking the extra 0
> on the end is very important. It would be somewhat horrendous if that 0
> could end up in a different binv entry from the "foo".
> 

The part with adding cstring zero termination sounds a bit error prone and dangerous.
I would suggest a length byte (bytes) and checking and use an API where you pass length instead.
(strncpy/memcpy instead of strcpy etc)


> How about:
> 
> d) D = <<1>>, port_command(Port, [<<D/binary, 0, <<255>>/binary, <<"wibble">>/binary>>])
> 
> Is it safe to rely a binary being an atomic unit?
> 

If you mean that the binary parts are not split? then yes.
But as you know the binaries may be ProcBin or HeapBin (you do not really know)

/Tony
> 


More information about the erlang-questions mailing list