binary to string
Kent Boortz
kent@REDACTED
Sat Dec 28 19:13:50 CET 2002
"Inswitch Solutions - Erlang Evaluation" <erlang@REDACTED> writes:
> I'm need convert binary to string, but I don't want use
> list_to_atom(binary_to_list(Bin)) because the atom it's not garbage
> collector. It is possible to do this?
In Erlang strings are lists of integers so converting a binary
to a string (given that the binary is something that you can view
as a string) is just
binary_to_list(Bin)
Strings are not an efficient data type in Erlang but for most
applications they work ok. These are all the same "string" only
written differently
"foo"
[102,111,111]
[$f, $o, $o]
[$f, $o, $o | [] ]
[$f, $o | [$o | [] ]]
[$f | [$o | [$o | [] ]]]
and takes 24 bytes on the heap on a 32 bit machine,
kent
More information about the erlang-questions
mailing list