[erlang-questions] Binary string literal syntax
Lukas Larsson
lukas@REDACTED
Wed Jun 13 10:35:10 CEST 2018
On Tue, Jun 12, 2018 at 5:56 PM Tristan Sloughter <t@REDACTED> wrote:
> That would be great!
>
> Would there be much reason at all to use binary for text if this were the
> case now that utf is also supported?
>
It may still be better to use binaries as text if you don't do much
processing on the Erlang side, since the list would contain char() entries,
there is still en encoding cost to convert to utf-whatever that may want to
be avoided. Also you will read the data from somewhere which is probably
utf-something encoded, so at least when doing the initial parsing you will
deal with binaries.
I suppose it would still be optimal if one is passing around large chunks
> of >64 bytes of text, but besides that are there any performance reasons to
> use binaries over lists assuming the memory usage were the same?
>
I'm not sure.... One of the things that binaries are good at is matching
out sub binaries, i.e. taking <<"foo">> out of <<"foobar">> without having
to copy <<"foo">>. In order to do the same with lists a new syntax would
have to be added, something like [SubList:24/list | T] and a lot of support
in the run-time. Today there are 4 different types of binaries in the
run-time, while only 1 list type. If we go down this route we'll end up
with 3-4 list types as well, which of course adds to complexity in a lot of
places.
I'm fairly confident that we can get the cost of lists down to 8 bytes per
cons cell, but it will require re-writing a lot of code all over the place.
Getting it down even further will be even more difficult.... but not
impossible I think.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180613/37baeb26/attachment.htm>
More information about the erlang-questions
mailing list