I’m trying to create a C-Block that performs data comparison/accumulation across steps. I’m looking for a method that allows data persistence across the steps of the sim but is also unique to the specific instance of the C-Block.
I can’t use an instance struct variable since it is destroyed at the end of each step.
I can use a DLL global var but it isn’t unique in a multi-instanced C-Block.
Note: I’m trying to avoid doing file writes because I want the collected data to be destroyed after the entire sim is completed. Besides, I suspect fopen()s and fwrite()s take more sim time.
Any ideas as to a good method? Preferably RAM-based.
First, if you open/close only once for each instance for each step and write data only at the end of the step, file overhead is inconsequential.
Next, you don’t have to release per-instance data at the end of a step. You could use a global class/struct to save an array of instance data pointers (and the instance name for disambiguation of multi-instance data). The array should be resizable (std::vector) since you know neither the number of instances nor steps in advance (well, you can get the number of expected steps). At the end of processing, you’d step through the array and accumulate the data. You could release the instance data memory or, if not, it will be released when the simulation terminates.
I’m sure that we could think of more solutions if those prove unacceptable.
If that’s not enough to get you started, give us a bit more detail/examples for better solutions/examples.
Will QSpice or the dll termination automatically terminate memory allocated?
I noticed Destroy() has a Free(inst). If I comment out the Free(inst) in Destroy(), will there be a memory leak?
As I understand things, the QSpice GUI launches QSpice64.exe or QSpice80.exe to run the simulation as a separate process. That process loads the DLL. Any resources that you allocate within the DLL (memory, file handles, etc.) belong to the process and are released when the process terminates.
So, no, you should not leak memory between simulations. You’ll only leak memory during the simulation. But if you are intentionally not releasing the memory during the simulation, it’s not really a leak…
So you just want to know if Windows reclaims everything allocated during the run when the sim process ends? Not sure – if it didn’t, that would be a Windows-level bug wouldn’t it?
Googling “how to find memory leaks on windows 11” lists a number of things to look into.