[erlang-questions] constructing binaries question

Eric Merritt <>
Thu Sep 14 22:23:09 CEST 2006


If your pieces are already lists (strings) leave them as lists. You
can still do the lists of lists thing, it works exactly like the list
of binaries. Also the conversion will probably be more efficient in
the io layer then up in you app. Weather or not this balances out the
cost of coping is a good question, but not one that can be answered
with out doing a bit of profiling in a running application.  So just
leave your individual parts in whatever format they are already in
build them up into a list.

On 9/14/06, Yariv Sadan <> wrote:
> I think your solution will work for me. The final goal is to send the
> query to a socket, so the structure doesn't matter for pattern
> matching. However, I do have to send the query after it's constructed
> to an intermediate gen_server, which then sends the query to a process
> that owns the socket. I know that sending binary messages involves
> less copying than sending other types of messages, so I'm tempted to
> construct the queries as binaries before sending them anywhere.
>
> What's the best approach in this scenario?
>
> Thanks
> Yariv
>
> >
> >   It depends on what you want to do with it. Most of the io functions
> > understands lists of binaries. That being the case I usually just
> > build up a list of binaries and give it directly to the io function.
> > If you are passing the binaries around in your function then a list of
> > binaries may not be a good choice, because it makes pattern matching
> > the binary much more difficult (you don't know where the boundaries of
> > each piece are so you can't assume a contiguous binary for matching).
> >
>



More information about the erlang-questions mailing list