mxMalloc returns 0xffffffffe03c9460 which I cannot access

Hey there,
I use the NURBs-Toolbox and there are two options, 1 is to use Matlab Files, which is slow but works and the second is use C-Files:
So the Toolbox is about 10 years old, so this could be a problem. If I run the mex-files I get segfaults. So I tried to debug them and the fault is always the same: mxMalloc returns a pointer with 0xffffffff and then something. And then I can't access this array.
double *left = (double*) mxMalloc((p+1)*sizeof(double));
Is the call. The initializing fails, if mxMalloc returns an address at the end of the 48bit area.
I run Ubuntu 10.10 64bit with 64bit Matlab R2010b. Do i compile the files the wrong way or do I have to make some changes because of 64bit pointers?
Thanks
Philipp

 Risposta accettata

#include "mex.h"
was missing. I feel silly.
Thanks

2 Commenti

Impressive! The compiler does not show any warnings and is able to compile the file?! Which compiler do you use?
Likely OP just made function calls w/o any special types used in the code (e.g., mwSize etc.). So the missing prototypes for mxMalloc etc would just generate ("assuming int return" etc) warnings and not errors.

Accedi per commentare.

Più risposte (1)

Jan
Jan il 12 Apr 2011
Storing the result of an mxMalloc call in an "int" can fail on 64-bit machines: The replied value has 64 bits, the "int" has 32 bits only - usually.
So be sure to use 64 bit variables whenever it is necessary: most of all mwSize, mwIndex, mwSignedIndex are helpful. I've seen an example here, where "ptrdiff_t" helped: Answers: BLAS in mex files

1 Commento

double *left = (double*) mxMalloc((p+1)*sizeof(double));
This is the Call. Should have posted this earlier. If I initialize the left[0] I get the Segfault.
Thanks.

Accedi per commentare.

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by