Matlab Coder generated C/mex shallow copy

1 view (last 30 days)
I'm new to using MatLab Coder and am playing around with it to create MEX and C files. I currently have a simple function which swaps two variables i and f (which will be structs each containing an int16 array):
function [i,f] = structSwap(i,f) %#codegen
temp = f;
f = i;
i = temp;
end
I would like to have it so that the generated C code does a shallow copy by simply swapping the pointers to each struct. However, I cannot seem to find a way to do so - it looks like the code always comes out as a deep copy:
void structSwap(const emlrtStack *sp, struct0_T *i, struct0_T *f)
{
struct0_T temp;
emlrtHeapReferenceStackEnterFcnR2012b(sp);
emxInitStruct_struct0_T(sp, &temp, &b_emlrtRTEI, true);
emxCopyStruct_struct0_T(sp, &temp, f, &b_emlrtRTEI);
emxCopyStruct_struct0_T(sp, f, i, &c_emlrtRTEI);
emxCopyStruct_struct0_T(sp, i, &temp, &d_emlrtRTEI);
emxFreeStruct_struct0_T(&temp);
emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
static void emxCopy_int16_T(const emlrtStack *sp, emxArray_int16_T **dst,
emxArray_int16_T * const *src, const emlrtRTEInfo *srcLocation)
{
int32_T numElDst;
int32_T numElSrc;
int32_T i;
numElDst = 1;
numElSrc = 1;
for (i = 0; i < (*dst)->numDimensions; i++) {
numElDst *= (*dst)->size[i];
numElSrc *= (*src)->size[i];
}
for (i = 0; i < (*dst)->numDimensions; i++) {
(*dst)->size[i] = (*src)->size[i];
}
emxEnsureCapacity(sp, (emxArray__common *)*dst, numElDst, (int32_T)sizeof
(int16_T), srcLocation);
for (i = 0; i < numElSrc; i++) {
(*dst)->data[i] = (*src)->data[i];
}
}
Is there any option or method which I can use to make the coder perform a shallow copy instead by simply swapping the references?

Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!