ByteArr# - nullByteArr# anyone?

John Meacham john at
Thu Jan 25 21:35:11 EST 2007

On Wed, Jan 24, 2007 at 01:14:45PM +0000, Simon Marlow wrote:
> John Meacham wrote:
> >I would like to create a datatype that contains some memory managed by
> >the GHC runtime, the natural fit is ByteArr#, however, in the common
> >case, the ByteArr# won't actually have anything in it. would it be
> >possible to have a single constant 'nullByteArr#'? I can't define a top
> >level value of type ByteArr# and creating these values is in very
> >performance critical code so I am not quite sure what to do. It would
> >also be nice if byteArrContents# returned 'nullAddr#' for such byte
> >arrays, but it is not a strict requirement. 
> I guess you could use nullByteArr# = (unsafeCoerce# True) - that shouldn't 
> cause anything to go horribly wrong if you don't do any operations on it.  
> If you want a way to tell whether a particular ByteArr# is nullByteArr# or 
> not, then we'd have to elaborate the implementation of byteArrContents#.  
> None of this is particularly hard, if I've understood it correctly.

Cool, if that works then it is good enough for me. I was worried
that the garbage collector might do some type-based thing and get
confused to see a thunk when it expects an unboxed array.


John Meacham - ⑆⑆john⑈

More information about the Glasgow-haskell-users mailing list