[My apologies: some day - I promise - I'll learn to choose the right mailing
list... 8->]

On Mon, Oct 04, 1999 at 13:45:43 +0200, Sven Panne wrote:
[micro-marshalling]
> I know Manuel's code already and the one H/Direct produces. Has anybody
> else some FFI-related code and/or suggestions? This could be a wonderful
> topic for the wish list, but it would be nice to see the problems and needs
> for APIs different from GTK+ and OpenGL first.

Maybe it's worth to know how many objects a list has (without explicit
zeroElem), so I'd suggest to extend the class to:

   marshalList       ::        [a] -> IO Addr
   marshalListN      :: Int -> [a] -> IO Addr
   unmarshalList     ::        Addr -> IO [a]
   unmarshalListN    :: Int -> Addr -> IO [a]

where `marshalList' stores the list length at the beginning of the buffer,
like:

   marshalList xs = do
      let len     = length xs
          lenSize = sizeOf len
      buf <- malloc (lenSize + len * sizeOf (head xs))
      writeIntOffAddr buf 0 len
      zipWithM_ (writeOffAddr (buf `plusAddr` lenSize)) [ 0 .. ] xs
      return buf
      
and `instance Marshalable Int {...}'

> P.S. for the native speakers: Which spelling is correct, "marshaling" or
> "marshalling"? Ispell says "marshaling", but this looks a bit odd to me.

dictd knows both:
------------------------------------------------------------------------------
>From The Free On-line Dictionary of Computing (20Jul99) [foldoc]:
  marshalling
          <communications> (US -ll- or -l-) The process of packing one
          or more items of data into a {message buffer}, prior to
          transmitting that message buffer over a communication channel.
          The packing process not only collects together values which
          may be stored in non-consecutive memory locations but also
          converts data of different types into a standard
          representation agreed with the recipient of the message.
  marshaling
          <spelling> Alternative US spelling of "{marshalling}".
          (1998-03-16)
------------------------------------------------------------------------------    

I'd vote for the "double-L" variant... :-)


Cheers,
Michael
-- 
"Don't worry about people stealing your ideas.  If your ideas are any
 good, you'll have to ram them down people's throats."
                -- Howard Aiken

Reply via email to