Space problem: reading a list of records from a binary database
 
            Hi there,
While trying to read a list of records from a binary database I think I've 
encountered a space leak but I'm not proficient enough to detect the cause of 
the error.
The culprit is the readSessionDB function in SessionDB module which I attach 
with other relevant code.
What I do in Session.readSession is using FFI to read a fixed size record from 
an input stream. That far, okay. (I have no idea if I'm doing it right, 
though)
The problem is, combined with my approach in Session.readSessionDB, it results 
in huge amounts of space allocation, about 1MB, whereas the raw data would 
consume about 50K. It would be a [Session] with about 3000 elements, each of 
which contains 3 Ints and 6 Floats.
I wonder if the following code in SessionDB is the proper way to read a list 
of records from a file. I get the feeling that the (s:rest) in the last 
return statement causes my problems. 
readSessionList :: Handle -> IO [Session]
readSessionList h =
  do session <- readSession h
     case session of
          Nothing -> return []
	  Just s -> do rest <- readSessionList h
		       return (s:rest)
Comments appreciated,
-- 
Eray Ozkural (exa) 
 
            On Tuesday 28 May 2002 15:24, Eray Ozkural wrote:
Hi there,
While trying to read a list of records from a binary database I think I've encountered a space leak but I'm not proficient enough to detect the cause of the error.
Thanks to dennisb from #haskell strict flags on Session type solves my problem 
to a great extent but I still feel a lot of space inefficiency. Somebody care 
to give some advice on the code?
Regards,
-- 
Eray Ozkural (exa) 
participants (1)
- 
                 Eray Ozkural Eray Ozkural