Handling Pointers in C++ library
이전 댓글 표시
Hi, I am trying to write a c++ library for Matlab. There are 2 functions that Im having issues with. I am writing a wrapper for image acquisition and have 2 SDK functions
QueueBuffer(int handle, char* buffer, int size) and WaitBuffer(int handle, char** buffer, int size, int timeout)
I can create a libpointer in MatLab and pass it in, is there a way I can keep the pointer and pass them through to the SDK without having to copy the data or reallocate the space?
I can get it working with use of the following but Id rather not have this extra ineffiency and Im sure there is a better way to handle it: int yLength = mxGetN(prhs[2])+1; char TheString; TheString = (char)mxCalloc(yLength, sizeof(char)); mxGetString(prhs[2],TheString,yLength);
Any help is much appreciated.
댓글 수: 2
James Tursa
2011년 5월 20일
I assume you meant char * above, not char.
Krishna
2013년 9월 30일
Hi, I am trying to pass an image pointer from MEX file to another C-file to threshold the image in the C-file. The C-file has its own image type structure defined. Is it the problem of the header files or the library files as I have read somewhere? I can compile the code from matlab and can read the image. But the program breaks when I call the threshold function. Can I get some valuable suggestions. Thanks in advance.
답변 (2개)
Titus Edelhofer
2011년 5월 20일
0 개 추천
Hi,
hm, not sure I understand the question. For the second half: is the function mxArrayToString what you are looking for?
For the first half: how do you interact with your library? loadlibrary? Or mex files?
Titus
댓글 수: 2
David Gault
2011년 5월 20일
Kaustubha Govind
2011년 5월 20일
What type is AT_U8? Typically, you should just be able to use mxGetPr (for double*) or mxGetData (other types) to get the data in any mxArray and pass it on to other functions (be careful however, that the other library does not attempt to de-allocate the memory).
James Tursa
2011년 5월 20일
0 개 추천
MATLAB stores character data as 2-bytes per character. You can get a pointer to the character data with mxGetData, and pass that pointer down to your routine, but your routine will have to be able to handle the data as interleaved characters with a specified length (mxGetNumberOfElements) and will NOT be able to use it as a regular C-style NULL terminated string, which it isn't. If your routine must have a C-style NULL terminated string as input, then you are forced to copy the data ala mxArrayToString etc.
카테고리
도움말 센터 및 File Exchange에서 Call C++ from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!