MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Mathlink memory preservation

  • To: mathgroup at
  • Subject: [mg56455] Mathlink memory preservation
  • From: Bart Janssen <b.j.janssen at>
  • Date: Tue, 26 Apr 2005 01:33:00 -0400 (EDT)
  • Organization: Eindhoven University of Technology, The Netherlands
  • Sender: owner-wri-mathgroup at


I'm writing a C++ mathlink program that should do some image processing.

The main idea is:
1. Load the image into the memory of the mathlink module by 
PreLoadImage[Image__?(MatrixQ[#, NumberQ]&)]
2. Obtain a filter response from a filter parameterised by a couple of 
Reals (This way we don't have to send the entire image over the link 
over and over and thus obtain higher evaluation speeds).

After the preload function is called, the destructor of my image is 
magically called. Because of this the data is not available to the 
filter function.

How can I make sure my data stays in memory?
(Suggestions on improving the code are welcome too :) )

Source Code looks like this:
#include <mathlink and other stuff>

// global variable that holds the image that is processed
PixelMap<double> *image;

// Load the image data from mathematica into
// the global variable image
void preloadimage(){
         double* points;
         long *pdims;
         long prank;

         MLGetRealArray(stdlink, &points, &pdims,NULL,&prank);

         // Remove the old image from memory
         // Appearantly mathlink does this for me...
/*      if(image!=NULL)
                 delete image;

         image = new PixelMap<double>(pdims[1],pdims[0]);

         for(int y=0;y<pdims[0];y++)
                 for(int x=0;x<pdims[1];x++)

#ifdef DEBUG
         std::ofstream file ("/home/TUE/bjanssen/debug.txt");
         file << *image << std::endl;

	// some junk that for "some" reason has to be here

// Return a filter response from a filter
// applied on global image
// NOTE: preloadimage has to be called on forehand
void filter()
// ... same trickery as above, but then for other arguments
         double retval = filter(args,image);


Thanks in advance,
Kind Regards,
Bart Janssen

  • Prev by Date: Re: Format[ ] with \[OverBracket] in a package `Private` context
  • Next by Date: "large" matrices, Eigenvalues, determinants, characteristic polynomials
  • Previous by thread: Re: Using BarChart in a Widget
  • Next by thread: Re: Mathlink memory preservation