[racket] Racket Virtual Machine runs out of memory

From: Harry Spier (vasishtha.spier at gmail.com)
Date: Sat Jul 21 21:28:17 EDT 2012

1) I've changed my data representation of the output of
MagickExportImagePixels from a binary matrix of 0's and 1's to a
representation of just the black pixels as a list of rows, the black
pixels in each row represented by a pair giving the start and end
column positions of a contiguous black pixel strip.
I.e. '((row (black-pixel-strip-start-pos . black-pixel-strip-end-pos) ... ) ...)
This cuts the memory usage down immensely (at least 30 to 1) and in
fact simplifies my code, since I eventually produce a graph of
connected pixel strips with the pixel strips represented as above with
pointers added to other connected black pixel strips.

So Pierpaolo thank you, but I wont be needing a bit vector package after all.

2)
On Fri, Jul 20, 2012 at 10:53 PM, Eli Barzilay <eli at barzilay.org> wrote:
>you can just create a
> byte string of the appropriate size, then use it directly.  For
> example, I added this:
>
>   (defmagick* MagickExportImagePixels :
>     _MagickWand (x : _long) (y : _long) (width : _ulong) (height : _ulong)
>     (map : _string = "I") (storage-type : _StorageType = 'CharPixel)
>     (block : _bytes = (make-bytes (* width height)))
>     -> _status
>     -> block)
>
> (It's a bad hack, since it calls the function
> `MagickExportImagePixels' but it really hard-wires the `map' and
> `storage-type' arguments...)

Yes, MagickExportImagePixels uses the exact same interface as
"MagickGetImagePixels" and again yes it is the intensities and only
the intensities I export.

Is this slightly less of a hack but more importantly will it work.
If I add this to the ImageMagick FFI

(defwand* MagickExportImagePixels :
  _MagickWand (x : _long) (y : _long) (width : _ulong) (height : _ulong)
  (map : _string) (storage-type : _StorageType)
  ;; create the block, remember size and type
  (size  : _?       = (* width height (string-length map)))
  (type  : _?       = (StorageType->type storage-type))
  (block : _pointer = (malloc size type))
  -> _status
  ->  block)

So I can use it to produce the byte-string of intensities for this
application, but also leave its generality for other applications and
if I need to for other applications I can then also create a wrapper
function that calls this but takes its output and produces a list of
lists as you originally had it do.

Thanks,
Harry Spier

Posted on the users mailing list.