Wed, 16 Aug 2000 07:32:48 -0700, Simon Marlow <[EMAIL PROTECTED]> pisze:

> I'm not sure I understand; how does autoPtrToBytes work if it
> doesn't use a ForeignObj?

autoPtrToBytes:: Int -> IO (Ptr a)
autoPtrToBytes size = do
    ptr <- mallocBytes size
    addFinalizer ptr (free ptr)
    return ptr

> If you need internal pointers to a structure pointed to by a
> ForeignObj, then you'll need an arrangement of weak pointers to
> guarantee that the outer object is kept alive while the internal
> pointer is still in use. (actually the internal pointer could be
> a ForeignObj with a finalizer which just touches the outer object).

Ah, indeed. So plusAddr variants theoretically could be made safe,
while permitting attaching freeing finalizers to Addrs - but it would
be too expensive for every use, as in many cases touch placed after
the last use of the inner object is enough.

-- 
 __("<  Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK


Reply via email to