[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] Linking in Large ByteStrings

Subject: Re: [Haskell-cafe] Linking in Large ByteStrings
From: Svein Ove Aas
Date: Fri, 1 Jan 2010 17:49:50 +0100
On Fri, Jan 1, 2010 at 4:09 PM, 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?
>
In the limit, you can convert it to an assembly file.

Something like this, though I've done very little checking indeed of
the syntax. Consider this to be pseudocode.

foo.s
====

.global bytestring, bytestring_end
.label bytestring
.db 0x0c 0xdf 0xwhatever
.label bytestring_end

foo.hs
===
import Foreign
import Data.ByteString.Internal

foreign import ptr bytestring :: Ptr Word8
foreign import ptr bytestring_end :: Ptr Word8

yourString :: ByteString
yourString = unsafePerformIO $ do
  fptr <- newForeignPtr_ bytestring
  return $ fromForeignPtr (fptr, bytestring_end `minusPtr` bytestring,
0) -- ^ If I got the foreignPtr parameter order right


Unfortunately Data.ByteString.Internal, though still exported, is no
longer haddocked; this makes it hard to check the parameters. You
should go look up the 6.10.1 version's documentation, which is still
correct.

-- 
Svein Ove Aas
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

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