With Unicode, a string becomes a list of code points! ASCII is a thing of the past.<br>See <a href="http://www.erlang.org/doc/man/unicode.html">http://www.erlang.org/doc/man/unicode.html</a><br><br>But always remember, strings in general are not as easy as you think.<br>
<br>Robby<br><br><div class="gmail_quote">2012/3/5 Matthew Evans <span dir="ltr"><<a href="mailto:mattevans123@hotmail.com">mattevans123@hotmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div><div dir="ltr">
In a nut-shell a string in Erlang is represented as a list of (ASCII) characters. So "hello" becomes: [104,101,108,108,111].<div><br></div><div>This has many advantages in terms of been able to process strings. But there are problems:</div>
<div><br></div><div><span style="font-size:10pt">1)  It can take up lots of memory. A list is 1 word + 1 word for each element + size of element. So "hello" would (on a 64 bit machine) be 53 bytes.</span></div><div>
<span style="font-size:10pt"><br></span></div><div><span style="font-size:10pt">2) Many of the modules are implemented in Erlang (rather than in a BIF). Doing extensive string manipulation this way *could* be slow (when compared to C or other languages.</span></div>
<div><span style="font-size:10pt"><br></span></div><div><span style="font-size:10pt">Fortunately if you need performance you can represent strings as binaries (I personally think that we should be thinking strings as binaries all the time now).</span></div>
<div><span style="font-size:10pt"><br></span></div><div><span style="font-size:10pt">So the string "hello" would become <<"hello">> as a binary. The memory efficiency is much better than with lists (for anything over a few 10's of bytes it's pretty much "native" size - there is a small overhead IRC). Better still you can use the very fast binary module to do much of the processing. That with binary comprehensions and binary pattern matching allows you to buil powerful applications.</span></div>
<div><span style="font-size:10pt"><br></span></div><div><span style="font-size:10pt">Personally I've refactored much of my "string handling" code to use binaries now. What would be nice is for the "re" and "string" modules to allow binaries and lists as input.</span></div>
<div><span style="font-size:10pt"><br></span></div><div><span style="font-size:10pt">Matt   </span></div><div><br><div><div></div>> Date: Mon, 5 Mar 2012 17:49:48 +0400<br>> From: <a href="mailto:aleksandr.vin@gmail.com" target="_blank">aleksandr.vin@gmail.com</a><br>
> To: <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>> Subject: [erlang-questions] Strings usage caveats<div><div class="h5"><br>> <br>> Hello all,<br>> <br>
> I study Erlang strings usage in production. In<br>> doc/efficiency_guide/myths.html there is a paragraph that say<br>> "Actually, string handling could be slow if done improperly. In<br>> Erlang, you'll have to think a little more about how the strings are<br>
> used and choose an appropriate representation and use the re module<br>> instead of the obsolete regexp module if you are going to use regular<br>> expressions."<br>> <br>> I have a very poor experience in programming in Erlang/OTP so that<br>
> sentence was rather abstract for me. I suppose that the root of the<br>> problems with strings is in variables immutability and thus a copying<br>> of the whole source string in case of its modification. But it seems<br>
> to me that it's not that all.<br>> <br>> Can you please supply me with the sources to read or examples and<br>> hints about strings performance in Erlang.<br>> <br>> --<br>> Александр Винокуров<br>
> +7 (921) 982-21-43<br>> @aleksandrvin<br>> _______________________________________________<br>> erlang-questions mailing list<br>> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br></div></div></div></div>                                      </div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br>