[Haskell-cafe] Garbage collection and finalizer thread priority
simonmar at microsoft.com
Thu Jun 16 10:48:26 EDT 2005
On 13 June 2005 14:32, Gracjan Polak wrote:
> Simon Marlow wrote:
>> I presume you're running GHC. There's no way to increase the
>> priority of a thread - GHC's scheduler doesn't have a concept of
> Yes, I forgot to state it explicitly.
>> I would look into whether you can use mallocForeignPtr: this is much
>> faster than using newForeignPtr with finalizerFree, because the
>> memory is garbage collected directly and there's no need for a
> I use mallocBytes + reallocBytes + addForeignPtrFinalizer
> finalizerFree. I wouldn't think this is any different, thanks for
> your suggestion.
> May I ask where that difference comes from?
mallocBytes allocates memory using C's malloc(), which is expensive.
Also, the finalizer to free the memory is also expensive.
mallocForeignPtr on the other hand allocates memory directly in GHC's
heap (much faster than malloc()), and the memory is garbage collected
when it is no longer referenced, so there's no need for the finalizer.
Still, ForeignPtr is quite a bit slower than Ptr. We have some ideas
for improving it, which I'll hopefully get round to implementing
More information about the Haskell-Cafe