Defining a custom newByteArray primop that uses calloc?
Erik de Castro Lopo
mle+hs at mega-nerd.com
Thu Nov 27 01:55:29 UTC 2014
Brandon Simmons wrote:
> In my tests, using calloc from:
>
> https://hackage.haskell.org/package/missing-foreign-0.1.1/docs/Foreign-Marshal-MissingAlloc.html
>
> was about twice as fast as allocating and zeroing the same amount of
> memory with `newByteArray` + any of `copy/set/fillMutableByteArray`
> (all three were nearly identical). Is there a way I can reasonably
> define my own `newByteArray` that uses calloc?
>
> FWIW here are a couple of the benchmarks I'm working with in criterion:
>
> arrTestSet :: Int -> IO ()
> arrTestSet len = do
> let eBytes = (P.sizeOf (undefined::Int))*len
> a <- P.newAlignedPinnedByteArray
Why pinned memory?
Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
More information about the Glasgow-haskell-users
mailing list