haskell-opengl/OpenGL — Issue #22: PixelData stores a Ptr
Author: dagit
Created: 2012-01-14 19:27:03+00:00
State: open

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`.