Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Mathlink memory preservation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56488] Re: Mathlink memory preservation
  • From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 26 Apr 2005 21:52:47 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <d4kkpa$ebv$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

if you some where call the destructor it has nothing
to do with MathLink. MathLink knows nothing about your
C++ classes and will not touch it.

Regards
  Jens

"Bart Janssen" <b.j.janssen at tue.nl> schrieb im 
Newsbeitrag news:d4kkpa$ebv$1 at smc.vnet.net...
> Hello,
>
> 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).
>
> Problem:
> 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.
>
> Question:
> 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++)
> 
> image->SetPixel(x,y,points[pdims[1]*y+x]);
>
> #ifdef DEBUG
>         std::ofstream file 
> ("/home/TUE/bjanssen/debug.txt");
>         file << *image << std::endl;
>         file.close();
> #endif
>
> // some junk that for "some" reason has to be 
> here
>         MLNewPacket(stdlink);
>         MLPutInteger(stdlink,1);
> }
>
> //
> // 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);
>
>         MLNewPacket(stdlink);
>         MLPutReal(stdlink,retval);
> }
> //-----------------------------------------
>
> Thanks in advance,
> Kind Regards,
> Bart Janssen
> 



  • Prev by Date: Re: Re: Re: How do I remove operator status?
  • Next by Date: Re: Mathlink memory preservation
  • Previous by thread: Re: Mathlink memory preservation
  • Next by thread: Re: Mathlink memory preservation