[Haskell-cafe] FFI woes!

Sebastian Sylvan sebastian.sylvan at gmail.com
Sat Dec 18 09:08:44 EST 2004


On Sat, 18 Dec 2004 10:33:25 +0000, Keean Schupke
<k.schupke at imperial.ac.uk> wrote:
> I still think you need to use a StablePtr, so the sample will not get
> garbage collected.
> 
> You then need to free the sample explicitly when playback has finished...
> 
> Ideally you want to add a callback to do the free-ing. In my opinion if the
> library you are using does not provide this callback then the library is
> broken - and you should try and find a different library which does things
> properly.

I'm not sure why it doesn't do this, it provide a callback for streams.

Anyway, if I use polling to check if the sample is playing then I
don't need the stableptr because in the polling loop the channel will
be kept alive since it's used to check if its playing.


> There are too many unknowns to say much more than this... If you
> queue two samples to the same channel, how do you detemine
> when the first sample has finished (as polling the channed will
> tell you it is still playing).

I don't, basically. Well I could implement sort of a queue for each
channel but basically channels are resources and when you play a
sample it will just find a free channel for you. It's possible, but
not that useful, to do your own channel management.

> 
> I get the feeling the traditional way to manage this is to load _all_ the
> samples for a song/game level in one go, and keep them until the whole
> song or game-level is finished.
> 

Well that is how the C library does it, but if I could get the whole
"delay GC while channel is active" working it would amount to very
much the same thing, except a few resources might get freed up
earlier, and the programmer doesn't need to explicitly delete things.

/S


-- 
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell-Cafe mailing list