Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1GB Vector, will Vector.Unboxed give trouble, will Vector.Storable give trouble?

Tags:

haskell

We need to store a large 1GB of contiguous bytes in memory for long periods of time (weeks to months), and are trying to choose a Vector/Array library. I had two concerns that I can't find the answer to.

  1. Vector.Unboxed seems to store the underlying bytes on the heap, which can be moved around at will by the GC.... Periodically moving 1GB of data would be something I would like to avoid.

  2. Vector.Storable solves this problem by storing the underlying bytes in the c heap. But everything I've read seems to indicate that this is really only to be used for communicating with other languages (primarily c). Is there some reason that I should avoid using Vector.Storable for internal Haskell usage.

I'm open to a third option if it makes sense!

like image 315
jamshidh Avatar asked May 04 '15 19:05

jamshidh


1 Answers

My first thought was the mmap package, which allows you to "memory-map" a file into memory, using the virtual memory system to manage paging. I don't know if this is appropriate for your use case (in particular, I don't know if you're loading or computing this 1GB of data), but it may be worth looking at.

In particular, I think this prevents the GC moving the data around (since it's not on the Haskell heap, it's managed by the OS virtual memory subsystem). On the other hand, this interface handles only raw bytes; you couldn't have, say, an array of Customer objects or something.

like image 74
MathematicalOrchid Avatar answered Nov 03 '22 05:11

MathematicalOrchid