From: A B on
Hi

I'm trying to write a C++ mex file.
The prhs[0] is pass to the mex file is a vector of size n.
Inside my C++ code I need to make a type conversion.

At the moment I have something like:
double* test = mxGetPr(prhs[0]);

However the watch in Visual studio then shows the size of the pointer only as 1 value, which is the first value in the vector which I pass. Why is the information on the size of the vector lost?

How can I change this?

Thanks
From: James Tursa on
"A B" <gitsnedbutzi(a)hotmail.com> wrote in message <hujegj$8nc$1(a)fred.mathworks.com>...
> Hi
>
> I'm trying to write a C++ mex file.
> The prhs[0] is pass to the mex file is a vector of size n.
> Inside my C++ code I need to make a type conversion.
>
> At the moment I have something like:
> double* test = mxGetPr(prhs[0]);
>
> However the watch in Visual studio then shows the size of the pointer only as 1 value, which is the first value in the vector which I pass. Why is the information on the size of the vector lost?

mxGetPr returns a pointer to the first element. Use mxGetNumberOfElements to get the number of elements in the vector.

James Tursa
From: A B on
>
> mxGetPr returns a pointer to the first element. Use mxGetNumberOfElements to get the number of elements in the vector.
>
> James Tursa

Thanks, now I have another question. mxGetPr is a pointer to double values. Is it also possible to use a int vector in Matlab to pass to the mex function, and then get a pointer to the int values?

The reason I'm asking is because some of my C++ code needs int and I don't want to copy the values, as the vectors can get quiet large, up to a few hundred MB.
From: James Tursa on
"A B" <gitsnedbutzi(a)hotmail.com> wrote in message <hulu9o$is3$1(a)fred.mathworks.com>...
> >
> > mxGetPr returns a pointer to the first element. Use mxGetNumberOfElements to get the number of elements in the vector.
> >
> > James Tursa
>
> Thanks, now I have another question. mxGetPr is a pointer to double values. Is it also possible to use a int vector in Matlab to pass to the mex function, and then get a pointer to the int values?
>
> The reason I'm asking is because some of my C++ code needs int and I don't want to copy the values, as the vectors can get quiet large, up to a few hundred MB.

mxGetData gets a void pointer to the data, which you will have to cast as the appropriate pointer type on the C++ side. e.g., int32 will probably cast as (int *) on the C++ side, etc. mxGetImagData is the counterpart to mxGetPi. Since int (and other integer types) are not guaranteed to be the same size from platform to platform, you might consider using more generic types on the C++ side to guarantee the correct length integer is used, or at least check that whatever you are using is the correct length before using it.

James Tursa