Win32/Computer Memory Usage

Question 1, part 1 - When you write a program are the variables, etc, that you write in given a memory address when you compile the program?

Question 1 part 2 - Will those same addresses of memory contain those variables, even if the program is closed?

Question 1, part 3 - When you open the program again, does it use the same variables in the same memory addresses?

Question 2, part 1 - If you compile a program more than once, will it use the same memory for the same variables, etc, or new memory each time it is compiled?

Question 2, part 2 - If it uses new memory each time, is it possible to free the memory it used each other time it was compiled?

Question 3 - (I'm fairly certain I know the answer here, but I'll ask anyway) If you store user input into a variable, and then close the program, will those values remain the next time you run the program, or do you have to write them to a file, then load them in the next time it runs?

*These are more of computer tech questions, but I decided that I should ask here, instead of a computer tech forum, because I wanted to know if there was some type of coding I could use to solve any problems I might have.
1.1: For the most part no, variables are given an address when they are initiated.

1.2: Sometimes, but this is not reliable for say data recovery purposes as the system is free to use that RAM the millisecond your program is done.

1.3: No? This question feels awkward so I will skip it.

2.1: You seem to be confusing the term "compile" with the term "run" they are not mutually inclusive.

2.2: If you're asking what I think you are then this is the Operating Systems job, don't worry about it out side of runtime.

3: See question 1.2, but at the same time you may not get those same addresses, it's up to the Operating System.

Based on your questions I can tell you're excited about DMA (Direct Memory Access). But you are thinking about memory all wrong for the purposes of programming. You will never get usable data out of a freshley allocated block of memory that is only theoretically possible, in practice it would be like trying to guess what was at ground zero of an atom bomb right after it blows up.
In your answer to 1.2 you say the system is free to use that 'RAM', so all of the variables, etc, that are created by the program are stored in the RAM, rather than the physical memory? If this is the case then the other questions no longer apply. As to question 2, I am not confusing the two terms. When writing a program, I like to compile the program and test the parts I am currently working on, to make sure the entire thing is working, rather than finish the whole source code then go back and try to figure out what is wrong. So, I meant if you compile multiple times, not run. However, if the memory the system uses is Ram, which I believe is wiped when the power is cut, then it doesn't really matter after all. I just didn't want my computer's memory getting filled up with dead variables, etc, from multiple compilations, for testing purposes.
Memory IS RAM, when you are talking about using space on your Hard Drive then your PC does use this (it's called a page file) but even then it's a secondary storage medium and still only temporary so it will never "fill up".


As for question 2, I wanted to make sure you know that compiling the program is different from running it. You seem to understand this so you're all set in that regard.
Thank you so much for your help, it is greatly appreciated.
Topic archived. No new replies allowed.