major missing piece to arrays?

John Meacham john at repetae.net
Thu Jul 15 07:26:27 EDT 2004


Perhaps I am just missing something, but a major piece of efficient
array functionality seems to be missing. Namely the ability to
efficiently copy spans of arrays into one another and/or compare spans
of memory. (basically memcpy and memcmp from C). 

any particular reason these basic building blocks were left out? I am
trying to write an efficient packed string library and having to go
through intermediate lists kills the garbage collector as well as the
overall speed of my program. 

Ideally concatination should be a simple alloc + pair of memcpys. (yeah,
I know they are both of linear order, but the constant factor on a
system tuned assembler memcpy vs. chugging of the STG-machine is
absurdly different when cache is taken into account) 

So, my question is also, as a workaround for the moment, how might I
implement these rountines (without resorting to rewriting all the array
functionality with Foreign)?

Looking at the implementations of arrays, they all seem to be built on
ByteArray#'s, if I could get a (Ptr a) out of them, that would be ideal,
but I imagine that might be problematic without some mechanism to
temporarily pin the address in place so the GC doesn't move it.

I am thinking a family of routines. (with psuedosignatures)

copySpan: range -> MArray -> whereto -> MArray -> m ()
extractSpan : range -> IArray -> IArray
extractSpanM : range -> MArray -> m IArray
saveSpan : range -> IArray -> whereto -> MArray -> m ()

hopefully the meaning of all is clear... perhaps better names can be
come up with though. A similar set of routines which perform 'memcmp'
would also be useful, but less vital at the moment.

Sorry if I am just blind and missing these rountines...

        John



-- 
John Meacham - ⑆repetae.net⑆john⑈ 


More information about the Glasgow-haskell-users mailing list