C

Asked • 06/16/19

ssSetOutputPortWidth - does it allocate memory? Can we force that it is contiguous?

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 <code>mdlInitializeSizes</code>: ssSetOutputPortWidth(S, 0, 500000); ssSetOutputPortDataType(S, 0, SS_UINT8); Later, in <code>mdlOutputs</code>, 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 <code>ssSetInputPortRequiredContiguous</code> 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!

1 Expert Answer

By:

Kevin T. answered • 01/09/25

Tutor
New to Wyzant

Mathematics & Programming for all!

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.