I am writing a C S-function in Simulink/Matlab, which fills an output buffer of size 500 kB for a later application. I have done this in mdlInitializeSizes
:
ssSetOutputPortWidth(S, 0, 500000);
ssSetOutputPortDataType(S, 0, SS_UINT8);
Later, in mdlOutputs
, I am writing into the buffer as:
uint8_T *payload = (uint8_T*) ssGetOutputPortSignal(S,0);
for (uint32_T i = 0; i < 500000; ++i)
{
payload[i] = ...;
}
My questions are:
- Are those 500000 bytes safely allocated with the code I posted?
- Are those 500000 bytes contiguous? I know I can do
ssSetInputPortRequiredContiguous
for inputs, but I didn't find that option for outputs... - Is it safe/legit to fill in the output array like this? Is there a better way of doing this?
I am asking this because right now the code crashes when I try to write at positions larger than ~128k. This is a rough estimate I got through lots of trials, since this code runs on an embedded system that doesn't really provide error traces.
Thanks in advance!