[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C mex interface mxSetPr

From: louisranjard
Subject: C mex interface mxSetPr
Date: Thu, 6 Dec 2007 19:17:48 -0800 (PST)

Hi there,

I have a question relative to a C mex function.
I've written a C mex function which works properly with matlab (and octave)
on my machine but crashes on other machines with octave (don't know about
Basically, what happens is that it compiles ok (with mex in octave), run
fine once and then any more command produce a crash of octave which exits
with a segmentation fault.
I checked this function with valgrind and it looks ok so I think it comes
from the mex interface.

The function returns a pointer on a matrix dynamically allocated. Here is
schematically the part of the function which I think produces the problem
(part of mexFunction):

double *mata;
plhs[1] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL);
mata = function(); # returns a ptr declared with mxMalloc in the function

Interestingly if I free the pointer mata (adding mxFree(mata) ) it doesn't
crash but I loose the first value of the returned matrix.

I don't understand why it's working on my machine (fedora 6, 64bits, octave
2.9.9) and not others (32 or 64bits, fedoras, octave 2.9.15).

Does anyone have any idea of what I'm doing wrong or what is going on????
Where should I look for???
Should I rather write the function using DEFUN_DLD?? (any tips for doing
that??? Would it be faster by the way??)

Any help would be much appreciated!!

View this message in context:
Sent from the Octave - General mailing list archive at

reply via email to

[Prev in Thread] Current Thread [Next in Thread]