Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Saving The State Of A Pointer to a Struct

$
0
0
Hello Ever-So-Shrewd-Hackers,

I have an interesting programming problem of which I've never come across, but have a feeling that other people have. So I've created a struct that contains some member variables that will save the state of my calculations in real-time. I pass my object by-reference to the necessary functions so that all the members change their values within a global scope. Punchline: The object (and thus its members) is continually being modified within a loop, but there may arise a case where I need to save a static copy of the object (and thus its member)for further processing.

Question: How do I go about "saving" a copy of the object while it is continually being modified in the background? Essentially, I need to save a snapshot of the object's members in some sort of temporary object/variable.



typedef struct          // This structure will allow us to encapsulate all the pertinent information
{
  char* string;
  int  num1;
  float num2

}CoolDataType;


void main(void)

{
CoolDataType myVar;
int x = 50;
int y = 0;

 while(;;)/>
 {
  foo(&myVar);
  foo_bar(&myVar);
    
    y = randNumGenerator();        // Generates a number from 0-100 inclusive

    if (x > y)
    {
      // Save a static copy of myVar here, but how?!
    }
 }

return 0;
}







Thank you,

SB

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>