Simon Marlow wrote:
> Manuel M. T. Chakravarty wrote:
> [...] we should really enforce a stack discipline and use a wrapper
> > function:
> >   alloca :: Int -> (Addr -> IO a) -> IO a
> 
> Nice idea.  I'm not sure about the implementation though: did you
> have in mind using C's malloc/free?

Perhaps I'm totally missing the point here, but alloca seems to be
dead easy to me:

---------------------------------------------------------------
module Alloca(alloca) where

import Addr(Addr)

foreign import ccall "malloc" unsafe malloc :: Int  -> IO Addr
foreign import ccall "free"   unsafe free   :: Addr -> IO ()

alloca :: Int -> (Addr -> IO a) -> IO a
alloca n func = do
   addr <- malloc n
   val  <- func addr
   free addr
   return val
---------------------------------------------------------------

It's getting tough if you want to avoid malloc/free though.

But IMHO the main problem is the handling of the correct offsets for
e.g. inout parameters in the buffer. Alloca doesn't help here, and if
you do it by hand, you end up with Haskell code which look suspiciously
like the one H/Direct generates...

Cheers,
   Sven
-- 
Sven Panne                                        Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik                     FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen              Oettingenstr. 67
mailto:[EMAIL PROTECTED]            D-80538 Muenchen
http://www.informatik.uni-muenchen.de/~Sven.Panne

Reply via email to