O(n) Pack a null-terminated sequence of bytes, pointed to by an
Addr# (an arbitrary machine address assumed to point outside the
garbage-collected heap) into a
ByteString. A much faster way
to create an
Addr# is with an unboxed string literal, than to
pack a boxed string. A unboxed string literal is compiled to a static
char [] by GHC. Establishing the length of the string
requires a call to
strlen(3), so the
Addr# must point
to a null-terminated buffer (as is the case with
"string"#
literals in GHC). Use
unsafePackAddressLen if you know the
length of the string statically.
An example:
literalFS = unsafePackAddress "literal"#
This function is
unsafe. If you modify the buffer pointed to by
the original
Addr# this modification will be reflected in the
resulting
ByteString, breaking referential transparency.
Note this also won't work if your
Addr# has embedded
'\0' characters in the string, as
strlen will return
too short a length.