DLL Global Variables Preserved?


From today’s revision history: “12/31/2023 .DLL global variables are now preserved from .step to .step”.

Does this mean that C-Block DLL’s are now loaded / unloaded only at the start / end of the simulation run? (I’m not sure how else you’d retain DLL globals. Maybe not call DllMain() between steps?)

Do I correctly assume that we will get Destroy() calls at the end of each step to allow freeing per-instance allocations between steps? Or is there some other mechanism?

Or am I totally misunderstanding the revision comments / implications?


1 Like


I’ve tested this new feature in C-block dlls. You can create a Global var in the module and it keeps the last known value in the var across steps. For example, this persistence across steps allows me to determine the first step is being executed. This solves Does a C block have knowledge of what step is being run?

The var is destroyed once the sim ends.


Thanks, Len. That’s not exactly what I was getting at.


Len, I’ve posted a link to code for a more robust approach to “knowing what step is being run” in the thread that you referenced above. Just FYI.