[Haskell-cafe] Sometimes pinned memory?

Gregory Crosswhite gcross at phys.washington.edu
Wed Nov 11 16:32:20 EST 2009

Thanks, Don.  What made me think that this might be possible was the  
existence of Foreign.StablePtr, since that seems to take a Haskell  
expression and pin it down.  Could this mechanism be harness to pin  
down arrays, or am I misunderstanding how it works? (Is StablePtr  
really just making a copy of the expression behind the scenes?)

My motivation for this is that I will be sweeping back and forth along  
a data structure that is chain of memory blocks (essentially a pointed  
list), with ~ 10 to 1000 beads.  At any given time I am only working  
with and updating one bead on the chain, so I am wondering if trying  
to use unpinned memory for the beads not in use would help by speeding  
up allocations and allowing the g.c. to rearrange their layout in  
memory.  Each bead has a few memory chunks ranging from ~ 100 bytes to  
possibly up to tens of kilobytes, depending on a scaling parameter on  
my algorithm.

Any thoughts?


On Nov 11, 2009, at 1:18 PM, Don Stewart wrote:

> gcross:
>> Hey everyone!  Do you have any suggestions for how I might allocate  
>> an
>> aligned block of memory that I can pin while making foreign calls,  
>> but
>> leave unpinned the rest of the time to potentially improve allocation
>> and garbage collector performance?  Or is this even a good idea?
> There's no pinned/unpinned memory. You have to pick one.
>  * Use a ForeignPtr to allocate pinned memory (mallocForeignPtr)
> if you want it mostly poinned. Otherwise, you'll need to copy from
> unpinned to pinned.
> -- Don

More information about the Haskell-Cafe mailing list