haskell-opengl / OpenGL

Haskell bindings to OpenGL
http://www.haskell.org/haskellwiki/OpenGL
BSD 3-Clause "New" or "Revised" License
147 stars 26 forks source link

PixelData stores a Ptr #22

Open dagit opened 12 years ago

dagit commented 12 years ago

There are use cases where storing a Ptr a makes sense and the caller will clean up the memory when done with it. For example, if the caller has a ForeignPtr already you might see code like this:

withForeignPtr ptr $ \p -> do
  let pd = PixelData ... p
  ...

Here, the withForeignPtr will clean up p when done with it and pd should not escape (it is undefined outside of withForeignPtr).

I could also imagine a case where the PixelData is created outside of a withForeignPtr and the creator wants to associate a finalizer with the pointer stored inside. For this reason it may make sense to have a variant of PixelData that supports ForeignPtr.