[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] Linking in Large ByteStrings

Subject: Re: [Haskell-cafe] Linking in Large ByteStrings
From: Judah Jacobson
Date: Fri, 1 Jan 2010 13:19:42 -0800
On Fri, Jan 1, 2010 at 7:09 AM, Tom Hawkins <[email protected]> wrote:
> I have a large tarball I want to link into an executable as a
> ByteString.  What is the best way to do this?  I can convert the
> tarball into a haskell file, but I'm afraid ghc would take a long time
> to compile it.  Is there any way to link constant data directly with
> ghc?  If not, what's the most efficient way to code large ByteStrings
> for fast compilation?

Possibly the simplest is to use unsafePackAddress or unsafePackAddressLen:


{-# LANGUAGE MagicHash #-}
module Const where

import Data.ByteString.Unsafe as U
import System.IO.Unsafe
my_bstr = unsafePerformIO $ U.unsafePackAddress  "abcdefg"#


This trick of embedding raw strings (of type Addr#) is how happy and
alex store their parser lookup tables in the modules they generate.
I haven't seen any performance issues with it myself.

Hope that helps,
-Judah
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>