[racket] Racket Virtual Machine runs out of memory

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Jul 20 22:53:46 EDT 2012

8 hours ago, Harry Spier wrote:
> I probably have to go the route you and others suggest.  But I think
> I still have a problem.  Even the single operation of
> MagickExportPIxels to export the pixel data of this page to
> manipulate fills at least 4/7 of the memory before failure.  And
> there is no guarantee that pages wont have more pixel data.  They
> probably will.  And as Matthias says the list doesn't seem "that
> large".

It looks like `MagickExportPixels' is something similar to the
deprecated `MagickGetImagePixels' -- so my guess is that you
interfaced this function in a similar way to how the latter is done in
ffi/examples/magick.  If these guesses are all valid, then the
important thing here is that there's no real need to convert the
resulting block of memory to a list of lists -- 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...)

With this, calling the function on an image returns a byte string with
the intensities (which is also -- I'm guessing -- what you're looking
for).  Now you can use the resulting byte string as-is, and directly
read its contents, manipulate it, and use it with other magick
functions.  This will save you on the redundant list allocation, and
will keep a single copy instead of several copies.  (And perhaps
there's also some magick function that can do the same with a single
bit/pixel to get the extra 8x saving factor.)

> Also I have 4 or 5 transformation stages of the pixel data.  Will
> putting in Garbage Collection commands to get rid of transformations
> of the data I've already used help?

(My guess is that it won't help.)

> What sets the amount of memory the Racket virtual machine uses.  Is
> it a Racket parameter, Is it a function of the amount of RAM in the
> machine?  Is this more a Windows problem and will switching to Linux
> help etc.?

If you're not using a 64 bit machine, then it might help to do that,
but I'd put this in the same category of not worth fighting with,
since you'll need some drastic changes anyway.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.