alejandrojginerd Posted March 13 Share Posted March 13 Inside a BgCPLC I have created a nodetree that was dynamically allocated. I am trying to implement a way to free up this memory when the BgCPLC is disabled. As no code will the run when the cplc is disabled ithought of freeing the memory the next time it is enabled, therefore I need to keep track of the previeus UserAlgo.BgCplc[i] state. I thougt of having another CPLC running that stores the UserAlgo.BgCplc[i] value into a shared P variable but this seems to be an excesivelly cumbersome solution. Is there a cleaner way to achive this behaviour? #include <stdbool.h> static bool initialized; int user_plcc() { if (prev_UserAlgoBgCplc[i] = 0 && initialized){ // if it was previusly turned off and its not the first run free(root); initialized = false; } if (!initialized) // initialize the node tree { // Constructing the tree root = createNode(node, num_children) // fills the node using malloc depending on the number of children initialized = true; } if (prev_UserAlgoBgCplc[i] = 0 && !initialized){ // if it was previusly turned off and its not the first run free(root); } } Quote Link to comment Share on other sites More sharing options...
DaveBarnett Posted March 13 Share Posted March 13 The way I cleanly shut down background C programs is to have a global var that I set in script that instructs the C program to clean up and exit. ‘Downside is C program must be continually monitoring that var. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.