[Haskell-cafe] Packing Haskell values into a C array

Michael Baker michaeltbaker at gmail.com
Sat Apr 26 18:24:00 UTC 2014

I'm working on a game in Haskell and I'm at a point where I have to do some
optimization so I'm looking for advice or resources from people who may
have already solved my problem.

Specifically, I have a grid of 10,000 circles and I need to get them
rendered. This involves translating the 10,000 circles into a single C
array (of CFloats in my case) so that I can ship that array    off to
OpenGL for rendering. This is something I can't change, that's just the way
OpenGL works.

What I can change is the way I create and maintain the array. Currently I'm
doing the most naive thing I can, which is to convert the list of circles
into a list of floats, and then convert that list    into a C array every
frame. This is obviously very expensive.

I've thought of several things to try including:
  * Only allocate an array when the number of circles changes.
  * Convert a circles into a C struct and "poke" them directly into an
existing array instead of going through the intermediate form of a list.
  * Do some manual memory management and index each circle into a
preallocated array, only updating the values of the array that correspond
to circles which have changed.

I'm wondering if there are already common solutions to this sort of problem
(packing a lot of Haskell values that might change each frame into an array
efficiently). Any resources that are tangential to this sort of thing would
also be nice. For instance, how I can use the type system to ensure that
the resulting array has the shape I want.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140426/f928b4ac/attachment.html>

More information about the Haskell-Cafe mailing list