Re: Re[2]: [Haskell-cafe] bytestring vs. uvector

2009-03-14 Thread Duncan Coutts
On Fri, 2009-03-13 at 20:30 +0300, Bulat Ziganshin wrote:
> Hello Don,
> 
> Friday, March 13, 2009, 8:08:57 PM, you wrote:
> 
> >> What is the reason why you have decided to use unpinned arrays
> >> (ByteArray#) instead of pinned arrays (Foreign.Ptr)?
> 
> > They prevent heap fragmentation (and in general are faster).
> 
> you probably mean faster alloc/gc operations, everything else should
> be the same

Right. Access times are the same. Both are just pointers internally. It
is just the allocation time, GC time and extra memory use and lower
cache utilisation caused by heap fragmentation.

For big arrays it doesn't make much difference. Big ByteArray#
allocations get pinned anyway. For small ones, like strings I expect the
difference is much more noticeable, though I have not measured it.

Using ByteArray# also means we can use ST/runST rather than
IO/unsafePerformIO. In general we should prefer heap allocated byte
arrays and ST unless we really really want to always use pinned
allocations to interact with C libs easily.

Duncan

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Re[2]: [Haskell-cafe] bytestring vs. uvector

2009-03-14 Thread Duncan Coutts
On Tue, 2009-03-10 at 23:55 +0300, Bulat Ziganshin wrote:

> starting with 6.6, ForeignArray access is no-op, so we can just use
> obvious Ptr operations (via Storable class) to get unboxed arrays fast
> access. so, no more need for those special ByteArray# access operations
> 
> but Array library still old, so any effort based on its spources, got
> the same restrictions
> 
> also, ByteArray# may be unpinned, but afaik, this isn't really
> important - it can be coerced to Ptr for the period of one operation

Actually the fact that they may be unpinned is really important for
small allocations like short strings. Pinned allocations are slow and
lead to heap fragmentation.

Duncan

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe