フィルターのクリア

How to free memory from C-code in simulink embedded matlab code block

4 ビュー (過去 30 日間)
Rodrigo Lopez Negrete
Rodrigo Lopez Negrete 2022 年 6 月 28 日
回答済み: Walter Roberson 2022 年 6 月 28 日
Hi all,
I have an embedded matlab code block in a simulink simulation that makes calls to c functions to allocate memory and do some calculations. For example the code below: assume varA, varB are data structures created and allocated in C using the memallocfun function call.The types are defined in C.
persistent firstCall varA varB
if isempty(firstCall)
firstCall =1;
varA = coder.opaque('somestruct1 *','NULL','HeaderFile','defs.h');
varB = coder.opaque('somestruct2 *','NULL','HeaderFile','defs.h');
coder.ceval('memallocfun',coder.ref(varA),coder.ref(varB));
end
coder.ceval('workfun',coder.ref(varA),coder.ref(varB));
This code works and runs properly. My issue is that after the simulation is done I'd like to free the memory that was allocated by memallocfun. Should I do that in the StopFcn callback? Will StopFcn have access to the persistent variables created here? Otherwise, where should I free the memory created by C?
thanks!
Rodrigo

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 6 月 28 日
StopFcn will not have access to the persistent variables. Use global and a datastore

カテゴリ

Help Center および File ExchangeSources についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by