major missing piece to arrays?

Simon Marlow simonmar at
Mon Jul 19 05:15:50 EDT 2004

On 17 July 2004 01:47, John Meacham wrote:

> so, ByteArray# seems to be equivalant to a raw pointer in speed, with
> the advantage that it is garbage collected.
> however foreignptrs are twice as slow! and even slower than an IORef.

Were you using mallocForeignPtr here?  Or newForeignPtr?

> as a tangent..
> I have been using the
> counter :: Ptr Int
> counter = unsafePerformIO (new 0)
> trick to create fast global counters in performance critical stuff, it
> seems to work quite well. it would be nice if there were a way to
> allocate the memory staticaly though, because then counter could be a
> constant and should be much faster.
> perhaps something like the
> "foo"# :: Addr#  trick? like
> foreign data counter 4 :: Ptr Int
> to reserve 4 bytes in the bss... hmm..

You could allocate the variable statically in C, and use
  foreign import "&foo" :: Ptr Int

That should be nice & fast to access.


More information about the Glasgow-haskell-users mailing list