Re: c mex file problem -- incorrect results



On Thu, 05 Jul 2007 23:15:42 -0400, kendall wrote:

Dan Hensley wrote:


Sounds like a buffer overrun to me. The reason it works in standalone
mode is probably because you just call it once and then exit. In Matlab
the mex file stays resident in memory.

You might want to look at a tool such as memwatch (Google for it).

Dan


Thanks Dan. I tried memwatch, both when compiling the stand-along code
(exe) and when creating the mex file, but unfortunately memwatch didn't
detect a problem in either case.

Try a few more things just to understand the nature of the problem.

Does it always give the correct answer the first time you launch Matlab
and execute your mex file? How about if you run it in a loop, but do a
'clear <mexfilename>' after each time you invoke the function?

If it always gives the correct answer for the above cases, then look
closer for a memory overrun.

I ran into one recently where I was allocating an int a[4], but I was
using a[0] through a[5] in my code. It ran fine for a long time, but I
noticed after recompiling and adding some code to a different part of the
function that I got inconsistent results from a variable unrelated to my
array. The compiler must have rearranged it so the variable in question
was situated in memory right after the array.

If none of that helps, I'm out of ideas without seeing the source.

Dan
.



Relevant Pages

  • Re: Suppress segmentation violation check/warning
    ... I am creating a pbuffer for offscren rendering (direct rendering - which would access the video memory) ... Is there at least a way for me to let my mex program access video memory only without warnings from matlab. ... How can I suppress the MATLAB Suppress segmentation violation check/warning? ... All my work in the mex file work fine when called from matlab. ...
    (comp.soft-sys.matlab)
  • Re: segmentation problem causes crash
    ... Something is corrupting MATLAB's memory, this is probably not a Windows ... First guess is a bad MEX file but I do not see any mex file use in a ... I wrote a matlab program which detects NALU headers in an h264 ...
    (comp.soft-sys.matlab)
  • Re: Suppress segmentation violation check/warning
    ... The mex file works perfectly well when compiled and run as a native ... but the written code does its work and frees the pbuffer memory - ... I guess matlab detects this writing to video memory and triggers the ...
    (comp.soft-sys.matlab)
  • Re: mex file, matlab crashes
    ... the mex file compiles smoothly and the first time i call the ... the matlab simply crashes (segment ... but there is some problem with memory ...
    (comp.soft-sys.matlab)
  • Re: Wishlist for R2007b
    ... via escape sequences; those are about the closest you are ... Matlab always runs as a single process, ... inform Matlab that K:\ (windows) which has a 250 GB ... drive can be used for up to 50 GB of virtual memory. ...
    (comp.soft-sys.matlab)