Handling Pointers in C++ library
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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 comentarios
  Krishna
 el 30 de Sept. de 2013
				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.
Respuestas (2)
  Titus Edelhofer
    
 el 20 de Mayo de 2011
        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 comentarios
  Kaustubha Govind
    
      
 el 20 de Mayo de 2011
				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
      
      
 el 20 de Mayo de 2011
        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.
0 comentarios
Ver también
Categorías
				Más información sobre Call C++ from MATLAB en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




