I have a function (C/C++) that returns a pointer to an array of variable size. E.g. like this:
DLL_EXPORT uint8_t* getBuffer(int* len) {
uint8_t* dummyBuffer = new uint8_t[l];
I assumed that I can define "len" as output argument and then use this as SHAPE for the output definition:
getBufferDefinition = addFunction(libDef, ...
"uint8_t * getBuffer(int * len)", ...
"MATLABName", "clib.MyLib.getBuffer", ...
"Description", "clib.MyLib.getBuffer Representation of C++ function getBuffer.");
defineArgument(getBufferDefinition, "len", "int32", "output", 1);
defineOutput(getBufferDefinition, "RetVal", "uint8", "len");
validate(getBufferDefinition);
Unforunately this gives the follwing error when running the defineMyLib.m script:
Error using clibgen.FunctionDefinition/defineOutput
Invalid shape 'len'. Shape value 'len' is not an integer type. Set shape to an array of one or more
argument names or fixed values of integer type representing the dimensions of 'RetVal'.
Is there a trick to slove this? (I guess, I could split this in two calls: First call to get the length, second call to get the pointer passing len as input argument. But this is obviously very ugly.)
How can a function return a variable-length c-array?